| OLD | NEW |
| 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 246 |
| 247 | 247 |
| 248 def transfer_extended_attributes(dependency_interface, dependency_interface_base
name): | 248 def transfer_extended_attributes(dependency_interface, dependency_interface_base
name): |
| 249 """Transfer extended attributes from dependency interface onto members. | 249 """Transfer extended attributes from dependency interface onto members. |
| 250 | 250 |
| 251 Merging consists of storing certain interface-level data in extended | 251 Merging consists of storing certain interface-level data in extended |
| 252 attributes of the *members* (because there is no separate dependency | 252 attributes of the *members* (because there is no separate dependency |
| 253 interface post-merging). | 253 interface post-merging). |
| 254 | 254 |
| 255 The data storing consists of: | 255 The data storing consists of: |
| 256 * applying certain extended attributes from the dependency interface | 256 * moving certain extended attributes from the dependency interface |
| 257 to its members | 257 to its members (deleting the extended attribute from the interface) |
| 258 * storing the C++ class of the implementation in an internal | 258 * storing the C++ class of the implementation in an internal |
| 259 extended attribute of each member, [PartialInterfaceImplementedAs] | 259 extended attribute of each member, [PartialInterfaceImplementedAs] |
| 260 | 260 |
| 261 No return: modifies dependency_interface in place. | 261 No return: modifies dependency_interface in place. |
| 262 """ | 262 """ |
| 263 merged_extended_attributes = dict( | 263 merged_extended_attributes = {} |
| 264 (key, value) | 264 for key in DEPENDENCY_EXTENDED_ATTRIBUTES: |
| 265 for key, value in dependency_interface.extended_attributes.iteritems() | 265 value = dependency_interface.extended_attributes.get(key) |
| 266 if key in DEPENDENCY_EXTENDED_ATTRIBUTES) | 266 if not value: |
| 267 continue |
| 268 |
| 269 merged_extended_attributes[key] = value |
| 270 # Remove the merged attributes from the original dependency interface. |
| 271 # This ensures that if other dependency interfaces are merged onto this |
| 272 # one, its extended_attributes do not leak through |
| 273 # (https://crbug.com/603782). |
| 274 del dependency_interface.extended_attributes[key] |
| 267 | 275 |
| 268 # A partial interface's members are implemented as static member functions | 276 # A partial interface's members are implemented as static member functions |
| 269 # in a separate C++ class. This class name is stored in | 277 # in a separate C++ class. This class name is stored in |
| 270 # [PartialInterfaceImplementedAs] which defaults to the basename of | 278 # [PartialInterfaceImplementedAs] which defaults to the basename of |
| 271 # dependency IDL file. | 279 # dependency IDL file. |
| 272 # This class name can be overridden by [ImplementedAs] on the partial | 280 # This class name can be overridden by [ImplementedAs] on the partial |
| 273 # interface definition. | 281 # interface definition. |
| 274 # | 282 # |
| 275 # Note that implemented interfaces do *not* need [ImplementedAs], since | 283 # Note that implemented interfaces do *not* need [ImplementedAs], since |
| 276 # they are implemented on the C++ object |impl| itself, just like members of | 284 # they are implemented on the C++ object |impl| itself, just like members of |
| 277 # the main interface definition, so the bindings do not need to know in | 285 # the main interface definition, so the bindings do not need to know in |
| 278 # which class implemented interfaces are implemented. | 286 # which class implemented interfaces are implemented. |
| 279 # | 287 # |
| 280 # Currently [LegacyTreatAsPartialInterface] can be used to have partial | 288 # Currently [LegacyTreatAsPartialInterface] can be used to have partial |
| 281 # interface behavior on implemented interfaces, but this is being removed | 289 # interface behavior on implemented interfaces, but this is being removed |
| 282 # as legacy cruft: | 290 # as legacy cruft: |
| 283 # FIXME: Remove [LegacyTreatAsPartialInterface] | 291 # FIXME: Remove [LegacyTreatAsPartialInterface] |
| 284 # http://crbug.com/360435 | 292 # http://crbug.com/360435 |
| 285 # | 293 # |
| 286 # Note that [ImplementedAs] is used with different meanings on interfaces | 294 # Note that [ImplementedAs] is used with different meanings on interfaces |
| 287 # and members: | 295 # and members: |
| 288 # for Blink class name and function name (or constant name), respectively. | 296 # for Blink class name and function name (or constant name), respectively. |
| 289 # Thus we do not want to copy this from the interface to the member, but | 297 # Thus we do not want to copy this from the interface to the member, but |
| 290 # instead extract it and handle it separately. | 298 # instead extract it and handle it separately. |
| 291 if (dependency_interface.is_partial or | 299 if (dependency_interface.is_partial or |
| 292 'LegacyTreatAsPartialInterface' in dependency_interface.extended_attribu
tes): | 300 'LegacyTreatAsPartialInterface' in dependency_interface.extended_attribu
tes): |
| 293 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( | 301 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( |
| 294 dependency_interface.extended_attributes.get( | 302 dependency_interface.extended_attributes.pop( |
| 295 'ImplementedAs', dependency_interface_basename)) | 303 'ImplementedAs', dependency_interface_basename)) |
| 296 | 304 |
| 297 def update_attributes(attributes, extras): | 305 def update_attributes(attributes, extras): |
| 298 for key, value in extras.items(): | 306 for key, value in extras.items(): |
| 299 if key not in attributes: | 307 if key not in attributes: |
| 300 attributes[key] = value | 308 attributes[key] = value |
| 301 | 309 |
| 302 for attribute in dependency_interface.attributes: | 310 for attribute in dependency_interface.attributes: |
| 303 update_attributes(attribute.extended_attributes, merged_extended_attribu
tes) | 311 update_attributes(attribute.extended_attributes, merged_extended_attribu
tes) |
| 304 for constant in dependency_interface.constants: | 312 for constant in dependency_interface.constants: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 # This loop may process the same interface many times, so it's | 345 # This loop may process the same interface many times, so it's |
| 338 # possible that we're adding the same attributes twice or more. | 346 # possible that we're adding the same attributes twice or more. |
| 339 # So check if there is a duplicate. | 347 # So check if there is a duplicate. |
| 340 for attr in inherited_unforgeable_attributes: | 348 for attr in inherited_unforgeable_attributes: |
| 341 if attr not in interface.attributes: | 349 if attr not in interface.attributes: |
| 342 interface.attributes.append(attr) | 350 interface.attributes.append(attr) |
| 343 referenced_interfaces.extend(interface_info.get('referenced_interfac
es', [])) | 351 referenced_interfaces.extend(interface_info.get('referenced_interfac
es', [])) |
| 344 interface_info['referenced_interfaces'] = sorted(set(referenced_inte
rfaces)) | 352 interface_info['referenced_interfaces'] = sorted(set(referenced_inte
rfaces)) |
| 345 merge_dict_recursively(interface_info, | 353 merge_dict_recursively(interface_info, |
| 346 {'cpp_includes': {component: cpp_includes}}) | 354 {'cpp_includes': {component: cpp_includes}}) |
| OLD | NEW |