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

Side by Side Diff: sky/engine/bindings/scripts/interface_dependency_resolver.py

Issue 922053002: Remove unused V8 integration code in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
OLDNEW
(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 """Resolve interface dependencies, producing a merged IdlDefinitions object.
30
31 This library computes interface dependencies (partial interfaces and
32 implements), reads the dependency files, and merges them to the IdlDefinitions
33 for the main IDL file, producing an IdlDefinitions object representing the
34 entire interface.
35
36 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler#TOC -Dependency-resolution
37 """
38
39 import os.path
40
41 # The following extended attributes can be applied to a dependency interface,
42 # and are then applied to the individual members when merging.
43 # Note that this moves the extended attribute from the interface to the member,
44 # which changes the semantics and yields different code than the same extended
45 # attribute on the main interface.
46 DEPENDENCY_EXTENDED_ATTRIBUTES = set([
47 'Conditional',
48 'RuntimeEnabled',
49 ])
50
51
52 class InterfaceDependencyResolver(object):
53 def __init__(self, interfaces_info, reader):
54 """Initialize dependency resolver.
55
56 Args:
57 interfaces_info:
58 dict of interfaces information, from compute_dependencies.py
59 reader:
60 IdlReader, used for reading dependency files
61 """
62 self.interfaces_info = interfaces_info
63 self.reader = reader
64
65 def resolve_dependencies(self, definitions):
66 """Resolve dependencies, merging them into IDL definitions of main file.
67
68 Dependencies consist of 'partial interface' for the same interface as
69 in the main file, and other interfaces that this interface 'implements'.
70 These are merged into the main IdlInterface, as the main IdlInterface
71 implements all these members.
72
73 Referenced interfaces are added to IdlDefinitions, but not merged into
74 the main IdlInterface, as these are only referenced (their members are
75 introspected, but not implemented in this interface).
76
77 Inherited extended attributes are also added to the main IdlInterface.
78
79 Modifies definitions in place by adding parsed dependencies.
80
81 Args:
82 definitions: IdlDefinitions object, modified in place
83 """
84 if not definitions.interfaces:
85 # This definitions should have a dictionary. Nothing to do for it.
86 return
87 target_interface = next(definitions.interfaces.itervalues())
88 interface_name = target_interface.name
89 interface_info = self.interfaces_info[interface_name]
90
91 if 'inherited_extended_attributes' in interface_info:
92 target_interface.extended_attributes.update(
93 interface_info['inherited_extended_attributes'])
94
95 merge_interface_dependencies(definitions,
96 target_interface,
97 interface_info['dependencies_full_paths'],
98 self.reader)
99
100 for referenced_interface_name in interface_info['referenced_interfaces'] :
101 referenced_definitions = self.reader.read_idl_definitions(
102 self.interfaces_info[referenced_interface_name]['full_path'])
103 definitions.update(referenced_definitions)
104
105
106 def merge_interface_dependencies(definitions, target_interface, dependency_idl_f ilenames, reader):
107 """Merge dependencies ('partial interface' and 'implements') in dependency_i dl_filenames into target_interface.
108
109 No return: modifies target_interface in place.
110 """
111 # Sort so order consistent, so can compare output from run to run.
112 for dependency_idl_filename in sorted(dependency_idl_filenames):
113 dependency_definitions = reader.read_idl_file(dependency_idl_filename)
114 dependency_interface = next(dependency_definitions.interfaces.itervalues ())
115 dependency_interface_basename, _ = os.path.splitext(os.path.basename(dep endency_idl_filename))
116
117 transfer_extended_attributes(dependency_interface,
118 dependency_interface_basename)
119 definitions.update(dependency_definitions) # merges partial interfaces
120 if not dependency_interface.is_partial:
121 # Implemented interfaces (non-partial dependencies) are also merged
122 # into the target interface, so Code Generator can just iterate
123 # over one list (and not need to handle 'implements' itself).
124 target_interface.merge(dependency_interface)
125
126
127 def transfer_extended_attributes(dependency_interface, dependency_interface_base name):
128 """Transfer extended attributes from dependency interface onto members.
129
130 Merging consists of storing certain interface-level data in extended
131 attributes of the *members* (because there is no separate dependency
132 interface post-merging).
133
134 The data storing consists of:
135 * applying certain extended attributes from the dependency interface
136 to its members
137 * storing the C++ class of the implementation in an internal
138 extended attribute of each member, [PartialInterfaceImplementedAs]
139
140 No return: modifies dependency_interface in place.
141 """
142 merged_extended_attributes = dict(
143 (key, value)
144 for key, value in dependency_interface.extended_attributes.iteritems()
145 if key in DEPENDENCY_EXTENDED_ATTRIBUTES)
146
147 # A partial interface's members are implemented as static member functions
148 # in a separate C++ class. This class name is stored in
149 # [PartialInterfaceImplementedAs] which defaults to the basename of
150 # dependency IDL file.
151 # This class name can be overridden by [ImplementedAs] on the partial
152 # interface definition.
153 #
154 # Note that implemented interfaces do *not* need [ImplementedAs], since
155 # they are implemented on the C++ object |impl| itself, just like members of
156 # the main interface definition, so the bindings do not need to know in
157 # which class implemented interfaces are implemented.
158 #
159 # Currently [LegacyTreatAsPartialInterface] can be used to have partial
160 # interface behavior on implemented interfaces, but this is being removed
161 # as legacy cruft:
162 # FIXME: Remove [LegacyTreatAsPartialInterface]
163 # http://crbug.com/360435
164 #
165 # Note that [ImplementedAs] is used with different meanings on interfaces
166 # and members:
167 # for Blink class name and function name (or constant name), respectively.
168 # Thus we do not want to copy this from the interface to the member, but
169 # instead extract it and handle it separately.
170 if (dependency_interface.is_partial or
171 'LegacyTreatAsPartialInterface' in dependency_interface.extended_attribu tes):
172 merged_extended_attributes['PartialInterfaceImplementedAs'] = (
173 dependency_interface.extended_attributes.get(
174 'ImplementedAs', dependency_interface_basename))
175
176 for attribute in dependency_interface.attributes:
177 attribute.extended_attributes.update(merged_extended_attributes)
178 for constant in dependency_interface.constants:
179 constant.extended_attributes.update(merged_extended_attributes)
180 for operation in dependency_interface.operations:
181 operation.extended_attributes.update(merged_extended_attributes)
OLDNEW
« no previous file with comments | « sky/engine/bindings/scripts/idl_validator.py ('k') | sky/engine/bindings/scripts/interfaces_info_individual.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698