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

Side by Side Diff: Source/bindings/scripts/idl_definitions.py

Issue 205873003: Refactor interface dependency resolution (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/scripts/idl_reader.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 # Resolve typedefs with the actual types and then discard the Typedefs. 141 # Resolve typedefs with the actual types and then discard the Typedefs.
142 # http://www.w3.org/TR/WebIDL/#idl-typedefs 142 # http://www.w3.org/TR/WebIDL/#idl-typedefs
143 self.resolve_typedefs(typedefs) 143 self.resolve_typedefs(typedefs)
144 144
145 def resolve_typedefs(self, typedefs): 145 def resolve_typedefs(self, typedefs):
146 for callback_function in self.callback_functions.itervalues(): 146 for callback_function in self.callback_functions.itervalues():
147 callback_function.resolve_typedefs(typedefs) 147 callback_function.resolve_typedefs(typedefs)
148 for interface in self.interfaces.itervalues(): 148 for interface in self.interfaces.itervalues():
149 interface.resolve_typedefs(typedefs) 149 interface.resolve_typedefs(typedefs)
150 150
151 def update(self, other):
152 """Update with additional IdlDefinitions."""
153 for interface_name, new_interface in other.interfaces.iteritems():
154 if not new_interface.is_partial:
155 # Add as new interface
156 self.interfaces[interface_name] = new_interface
157 continue
158
159 # Merge partial to existing interface
160 try:
161 self.interfaces[interface_name].merge(new_interface)
162 except KeyError:
163 raise Exception('Tried to merge partial interface for {0}, '
164 'but no existing interface by that name'
165 .format(interface_name))
166
151 167
152 ################################################################################ 168 ################################################################################
153 # Callback Functions 169 # Callback Functions
154 ################################################################################ 170 ################################################################################
155 171
156 class IdlCallbackFunction(TypedObject): 172 class IdlCallbackFunction(TypedObject):
157 def __init__(self, node): 173 def __init__(self, node):
158 children = node.GetChildren() 174 children = node.GetChildren()
159 num_children = len(children) 175 num_children = len(children)
160 if num_children != 2: 176 if num_children != 2:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 attribute.resolve_typedefs(typedefs) 250 attribute.resolve_typedefs(typedefs)
235 for constant in self.constants: 251 for constant in self.constants:
236 constant.resolve_typedefs(typedefs) 252 constant.resolve_typedefs(typedefs)
237 for constructor in self.constructors: 253 for constructor in self.constructors:
238 constructor.resolve_typedefs(typedefs) 254 constructor.resolve_typedefs(typedefs)
239 for custom_constructor in self.custom_constructors: 255 for custom_constructor in self.custom_constructors:
240 custom_constructor.resolve_typedefs(typedefs) 256 custom_constructor.resolve_typedefs(typedefs)
241 for operation in self.operations: 257 for operation in self.operations:
242 operation.resolve_typedefs(typedefs) 258 operation.resolve_typedefs(typedefs)
243 259
260 def merge(self, other):
261 """Merge in another interface's members (e.g., partial interface)"""
262 self.attributes.extend(other.attributes)
263 self.constants.extend(other.constants)
264 self.operations.extend(other.operations)
265
244 266
245 class IdlException(IdlInterface): 267 class IdlException(IdlInterface):
246 # Properly exceptions and interfaces are distinct, and thus should inherit a 268 # Properly exceptions and interfaces are distinct, and thus should inherit a
247 # common base class (say, "IdlExceptionOrInterface"). 269 # common base class (say, "IdlExceptionOrInterface").
248 # However, there is only one exception (DOMException), and new exceptions 270 # However, there is only one exception (DOMException), and new exceptions
249 # are not expected. Thus it is easier to implement exceptions as a 271 # are not expected. Thus it is easier to implement exceptions as a
250 # restricted subclass of interfaces. 272 # restricted subclass of interfaces.
251 # http://www.w3.org/TR/WebIDL/#idl-exceptions 273 # http://www.w3.org/TR/WebIDL/#idl-exceptions
252 def __init__(self, node): 274 def __init__(self, node):
253 # Exceptions are similar to Interfaces, but simpler 275 # Exceptions are similar to Interfaces, but simpler
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 child_class = child.GetClass() 642 child_class = child.GetClass()
621 if child_class != 'Type': 643 if child_class != 'Type':
622 raise ValueError('Unrecognized node class: %s' % child_class) 644 raise ValueError('Unrecognized node class: %s' % child_class)
623 return type_node_to_type(child) 645 return type_node_to_type(child)
624 646
625 647
626 def union_type_node_to_idl_union_type(node, is_nullable=False): 648 def union_type_node_to_idl_union_type(node, is_nullable=False):
627 member_types = [type_node_to_type(member_type_node) 649 member_types = [type_node_to_type(member_type_node)
628 for member_type_node in node.GetChildren()] 650 for member_type_node in node.GetChildren()]
629 return IdlUnionType(member_types, is_nullable=is_nullable) 651 return IdlUnionType(member_types, is_nullable=is_nullable)
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/idl_reader.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698