Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Unified Diff: Source/bindings/scripts/interface_dependency_resolver.py

Issue 15801003: IDL parser rewrite in Python (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Revised. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/scripts/interface_dependency_resolver.py
diff --git a/Source/bindings/scripts/interface_dependency_resolver.py b/Source/bindings/scripts/interface_dependency_resolver.py
index 27495c71f5d025eb8d591aaebf261e32c4c8c13a..cefda6591c4d0fbdf72b55d5c4754f132a157829 100644
--- a/Source/bindings/scripts/interface_dependency_resolver.py
+++ b/Source/bindings/scripts/interface_dependency_resolver.py
@@ -35,26 +35,31 @@ entire interface.
It also checks whether a file should have bindings generated, or whether
instead it is just a dependency.
-
-FIXME: Currently a stub, as part of landing the parser incrementally.
-Just computes dependencies, and should always return None, indicating
-bindings should not be generated.
-Does not read IDL files or merge IdlDefinitions yet.
"""
import os.path
+import idl_reader
-def merge_interface_dependencies(idl_definitions, idl_filename, interface_dependencies_filename, additional_idl_filenames):
- """Merges dependencies into an existing IDL document.
- Modifies idl_definitions in place by adding parsed dependencies, and checks
- whether bindings should be generated, returning bool.
+class InterfaceNotFoundError(Exception):
+ """Raised if (partial) interface not found in target."""
haraken 2013/07/22 01:50:23 Slightly better: "Raised if (partial) interface no
Nils Barth (inactive) 2013/07/22 06:32:01 Done.
+ pass
+
+
+class InvalidPartialInterfaceError(Exception):
+ """Raised if a file listed as a partial interface is not in fact so."""
+ pass
- FIXME: stub: parser not implemented yet
+
+def resolve_dependencies(definitions, idl_filename, interface_dependencies_filename, additional_idl_filenames, verbose=False):
+ """Resolves dependencies, merging them into an existing IDL document.
haraken 2013/07/22 01:50:23 Slightly better: "Resolves interface dependencies
Nils Barth (inactive) 2013/07/22 06:32:01 I've changed comment, rewording a bit.
+
+ Modifies definitions in place by adding parsed dependencies, and checks
+ whether bindings should be generated, returning bool.
Arguments:
- idl_definitions: IdlDefinitions object, modified in place
+ definitions: IdlDefinitions object, modified in place
idl_filename: filename of main IDL file for the interface
interface_dependencies_file: filename of dependencies file (produced by compute_dependencies.py)
additional_idl_files: list of additional files, not listed in interface_dependencies_file, for which bindings should nonetheless be generated
@@ -67,10 +72,18 @@ def merge_interface_dependencies(idl_definitions, idl_filename, interface_depend
dependency_idl_filenames = compute_dependency_idl_files(basename, interface_dependencies_filename, additional_idl_filenames)
if dependency_idl_filenames is None:
return False
- # FIXME: currently dependency_idl_files *must* be None (indicating that
- # dummy .cpp and .h files should be generated), as actual parser not
- # present yet.
- raise RuntimeError('Stub: parser not implemented yet')
+ # The Blink IDL filenaming convention is that the file <interface_name>.idl
+ # MUST contain the interface "interface_name" or exception "interface_name".
+ if interface_name in definitions.exceptions:
+ # Exceptions do not have dependencies, so no merging necessary
+ return definitions
+ try:
+ interface = definitions.interfaces[interface_name]
haraken 2013/07/22 01:50:23 Nit: interface => target_interface (for clarity)
Nils Barth (inactive) 2013/07/22 06:32:01 Fixed throughout.
+ except KeyError:
+ raise InterfaceNotFoundError('Could not find interface or exception "{interface_name}" in {basename}'.format(**locals()))
+ merge_interface_dependencies(interface, idl_filename, dependency_idl_filenames, verbose=verbose)
+
+ return definitions
def compute_dependency_idl_files(target_idl_basename, interface_dependencies_filename, additional_idl_filenames):
@@ -85,9 +98,6 @@ def compute_dependency_idl_files(target_idl_basename, interface_dependencies_fil
- Otherwise, return None. This happens when the given IDL file is a
dependency, for which we don't want to generate bindings.
"""
- if interface_dependencies_filename is None:
- return []
-
# The format of the interface dependencies file is:
#
# Document.idl P.idl
@@ -121,3 +131,42 @@ def compute_dependency_idl_files(target_idl_basename, interface_dependencies_fil
return []
return None
+
+
+def merge_interface_dependencies(interface, idl_filename, dependency_idl_filenames, verbose=False):
haraken 2013/07/22 01:50:23 Nit: interface => target_interface
Nils Barth (inactive) 2013/07/22 06:32:01 Done.
+ """Merge partial interfaces in dependency_idl_files into target_document.
haraken 2013/07/22 01:50:23 dependency_idl_files => dependency_idl_filename ta
Nils Barth (inactive) 2013/07/22 06:32:01 Done.
+
+ No return: modifies target_document in place.
haraken 2013/07/22 01:50:23 target_document => target_interface
Nils Barth (inactive) 2013/07/22 06:32:01 Done.
+ """
+ # Sort so order consistent, so can compare output from run to run.
+ for dependency_idl_filename in sorted(dependency_idl_filenames):
+ dependency_interface_name, _ = os.path.splitext(os.path.basename(dependency_idl_filename))
+ definitions = idl_reader.read_idl_file(dependency_idl_filename, verbose=verbose)
+
+ for dependency_interface in definitions.interfaces.itervalues():
+ # Dependency files contain either partial interfaces for
+ # the (single) target interface, in which case the interface names
+ # must agree, or interfaces that are implemented by the target
+ # interface, in which case the interface names differ.
+ if dependency_interface.is_partial and dependency_interface.name != interface.name:
+ raise InvalidPartialInterfaceError('%s is not a partial interface of %s. There maybe a bug in the the dependency generator (compute_depedencies.py).' % (dependency_idl_filename, idl_filename))
+ if 'ImplementedAs' in dependency_interface.extended_attributes:
+ del dependency_interface.extended_attributes['ImplementedAs']
+ merge_dependency_interface(interface, dependency_interface, dependency_interface_name)
+
+
+def merge_dependency_interface(interface, dependency_interface, dependency_interface_name):
haraken 2013/07/22 01:50:23 Nit: interface => target_interface
Nils Barth (inactive) 2013/07/22 06:32:01 Done.
+ """Merge dependency_interface into interface.
haraken 2013/07/22 01:50:23 Ditto.
Nils Barth (inactive) 2013/07/22 06:32:01 Done.
+
+ No return: modifies interface in place.
haraken 2013/07/22 01:50:23 Ditto.
Nils Barth (inactive) 2013/07/22 06:32:01 Done.
+ """
+ def merge_lists(source_list, target_list):
+ for element in source_list:
+ if dependency_interface.is_partial:
+ element.extended_attributes['ImplementedBy'] = dependency_interface_name
+ element.extended_attributes.update(dependency_interface.extended_attributes)
+ target_list.append(element)
+
+ merge_lists(dependency_interface.attributes, interface.attributes)
+ merge_lists(dependency_interface.constants, interface.constants)
+ merge_lists(dependency_interface.functions, interface.functions)
« Source/bindings/scripts/idl_validator.py ('K') | « Source/bindings/scripts/idl_validator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698