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

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

Issue 1257613003: bindings: Supports inheritance of [Unforgeable] attributes as accessor-type properties. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Minor fix Created 5 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 unified diff | Download patch | Annotate | Revision Log
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 interface_info['inherited_extended_attributes']) 112 interface_info['inherited_extended_attributes'])
113 113
114 resolved_definitions = merge_interface_dependencies( 114 resolved_definitions = merge_interface_dependencies(
115 definitions, 115 definitions,
116 component, 116 component,
117 target_interface, 117 target_interface,
118 interface_info['dependencies_full_paths'] + 118 interface_info['dependencies_full_paths'] +
119 interface_info['dependencies_other_component_full_paths'], 119 interface_info['dependencies_other_component_full_paths'],
120 self.reader) 120 self.reader)
121 121
122 inherit_unforgeable_attributes(resolved_definitions, self.interfaces_inf o)
123
122 for referenced_interface_name in interface_info['referenced_interfaces'] : 124 for referenced_interface_name in interface_info['referenced_interfaces'] :
123 referenced_definitions = self.reader.read_idl_definitions( 125 referenced_definitions = self.reader.read_idl_definitions(
124 self.interfaces_info[referenced_interface_name]['full_path']) 126 self.interfaces_info[referenced_interface_name]['full_path'])
125 127
126 for referenced_component in referenced_definitions: 128 for referenced_component in referenced_definitions:
127 if not is_valid_component_dependency(component, referenced_compo nent): 129 if not is_valid_component_dependency(component, referenced_compo nent):
128 raise Exception('This definitions: %s is defined in %s ' 130 raise Exception('This definitions: %s is defined in %s '
129 'but reference interface:%s is defined ' 131 'but reference interface:%s is defined '
130 'in %s' % (definitions.idl_name, 132 'in %s' % (definitions.idl_name,
131 component, 133 component,
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 for key, value in extras.items(): 300 for key, value in extras.items():
299 if key not in attributes: 301 if key not in attributes:
300 attributes[key] = value 302 attributes[key] = value
301 303
302 for attribute in dependency_interface.attributes: 304 for attribute in dependency_interface.attributes:
303 update_attributes(attribute.extended_attributes, merged_extended_attribu tes) 305 update_attributes(attribute.extended_attributes, merged_extended_attribu tes)
304 for constant in dependency_interface.constants: 306 for constant in dependency_interface.constants:
305 update_attributes(constant.extended_attributes, merged_extended_attribut es) 307 update_attributes(constant.extended_attributes, merged_extended_attribut es)
306 for operation in dependency_interface.operations: 308 for operation in dependency_interface.operations:
307 update_attributes(operation.extended_attributes, merged_extended_attribu tes) 309 update_attributes(operation.extended_attributes, merged_extended_attribu tes)
310
311
312 def inherit_unforgeable_attributes(resolved_definitions, interfaces_info):
313 """Inherits [Unforgeable] attributes and updates the arguments accordingly.
314
315 For each interface in |resolved_definitions|, collects all [Unforgeable]
316 attributes in ancestor interfaces in the same component and adds them to
317 the interface. 'referenced_interfaces' and 'cpp_includes' in
318 |interfaces_info| are updated accordingly.
319 """
320 def collect_unforgeable_attributes_in_ancestors(interface_name, component, u nforgeable_attributes=None, referenced_interfaces=None, cpp_includes=None):
321 if unforgeable_attributes is None:
322 unforgeable_attributes = []
323 if referenced_interfaces is None:
324 referenced_interfaces = []
325 if cpp_includes is None:
326 cpp_includes = set()
327 if not interface_name:
328 return unforgeable_attributes, referenced_interfaces, cpp_includes
329 interface = interfaces_info[interface_name]
330 attrs = interface.get('unforgeable_attributes', {}).get(component, [])
331 unforgeable_attributes.extend(attrs)
332 referenced = [attr.idl_type.base_type for attr in attrs
333 if attr.idl_type.base_type in
334 interface.get('referenced_interfaces', [])]
335 referenced_interfaces.extend(referenced)
336 cpp_includes.update(interface.get('cpp_includes', {}).get(component, {}) )
337 return collect_unforgeable_attributes_in_ancestors(
bashi 2015/07/28 00:38:47 How about merge-and-return recursive results (unfo
Yuki 2015/07/29 08:16:24 Done.
338 interface.get('parent'), component,
339 unforgeable_attributes, referenced_interfaces, cpp_includes)
340
341 for component, definitions in resolved_definitions.iteritems():
342 for interface_name, interface in definitions.interfaces.iteritems():
bashi 2015/07/28 00:38:47 Help me understand: len(definitions.interfaces) co
Yuki 2015/07/29 08:16:24 For some interfaces, it's greater than one. It see
bashi 2015/07/29 09:24:33 As chatted offline, this could be executed multipl
Yuki 2015/07/29 09:32:38 I've updated the code so that we don't add any dup
343 interface_info = interfaces_info[interface_name]
344 inherited_unforgeable_attributes, referenced_interfaces, cpp_include s = collect_unforgeable_attributes_in_ancestors(interface_info.get('parent'), co mponent)
345 interface.attributes.extend(inherited_unforgeable_attributes)
346 referenced_interfaces.extend(interface_info.get('referenced_interfac es', []))
347 interface_info['referenced_interfaces'] = sorted(set(referenced_inte rfaces))
348 cpp_includes.update(interface_info.get('cpp_includes', {}).get(compo nent, set()))
349 if 'cpp_includes' not in interface_info:
350 interface_info['cpp_includes'] = {}
351 if component not in interface_info['cpp_includes']:
352 interface_info['cpp_includes'][component] = set()
353 interface_info['cpp_includes'][component].update(cpp_includes)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698