Chromium Code Reviews| 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 try: |
| 266 if key in DEPENDENCY_EXTENDED_ATTRIBUTES) | 266 value = dependency_interface.extended_attributes[key] |
|
bashi
2016/04/15 05:50:54
value = dependency_interface.extended_attributes.g
Matt Giuca
2016/04/15 06:21:43
Done. (Though I think the exception checking style
| |
| 267 except KeyError: | |
| 268 continue | |
| 269 | |
| 270 merged_extended_attributes[key] = value | |
| 271 # Remove the merged attributes from the original dependency interface. | |
| 272 # This ensures that if other dependency interfaces are merged onto this | |
| 273 # one, its extended_attributes do not leak through | |
| 274 # (https://crbug.com/603782). | |
| 275 del dependency_interface.extended_attributes[key] | |
| 267 | 276 |
| 268 # A partial interface's members are implemented as static member functions | 277 # A partial interface's members are implemented as static member functions |
| 269 # in a separate C++ class. This class name is stored in | 278 # in a separate C++ class. This class name is stored in |
| 270 # [PartialInterfaceImplementedAs] which defaults to the basename of | 279 # [PartialInterfaceImplementedAs] which defaults to the basename of |
| 271 # dependency IDL file. | 280 # dependency IDL file. |
| 272 # This class name can be overridden by [ImplementedAs] on the partial | 281 # This class name can be overridden by [ImplementedAs] on the partial |
| 273 # interface definition. | 282 # interface definition. |
| 274 # | 283 # |
| 275 # Note that implemented interfaces do *not* need [ImplementedAs], since | 284 # Note that implemented interfaces do *not* need [ImplementedAs], since |
| 276 # they are implemented on the C++ object |impl| itself, just like members of | 285 # 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 | 286 # the main interface definition, so the bindings do not need to know in |
| 278 # which class implemented interfaces are implemented. | 287 # which class implemented interfaces are implemented. |
| 279 # | 288 # |
| 280 # Currently [LegacyTreatAsPartialInterface] can be used to have partial | 289 # Currently [LegacyTreatAsPartialInterface] can be used to have partial |
| 281 # interface behavior on implemented interfaces, but this is being removed | 290 # interface behavior on implemented interfaces, but this is being removed |
| 282 # as legacy cruft: | 291 # as legacy cruft: |
| 283 # FIXME: Remove [LegacyTreatAsPartialInterface] | 292 # FIXME: Remove [LegacyTreatAsPartialInterface] |
| 284 # http://crbug.com/360435 | 293 # http://crbug.com/360435 |
| 285 # | 294 # |
| 286 # Note that [ImplementedAs] is used with different meanings on interfaces | 295 # Note that [ImplementedAs] is used with different meanings on interfaces |
| 287 # and members: | 296 # and members: |
| 288 # for Blink class name and function name (or constant name), respectively. | 297 # 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 | 298 # Thus we do not want to copy this from the interface to the member, but |
| 290 # instead extract it and handle it separately. | 299 # instead extract it and handle it separately. |
| 291 if (dependency_interface.is_partial or | 300 if (dependency_interface.is_partial or |
| 292 'LegacyTreatAsPartialInterface' in dependency_interface.extended_attribu tes): | 301 'LegacyTreatAsPartialInterface' in dependency_interface.extended_attribu tes): |
| 293 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( | 302 merged_extended_attributes['PartialInterfaceImplementedAs'] = ( |
| 294 dependency_interface.extended_attributes.get( | 303 dependency_interface.extended_attributes.get( |
| 295 'ImplementedAs', dependency_interface_basename)) | 304 'ImplementedAs', dependency_interface_basename)) |
| 305 try: | |
|
bashi
2016/04/15 05:50:54
if 'ImplementedAs' in dependency_interface.extende
Matt Giuca
2016/04/15 06:21:43
That way involves looking up the value in the dict
| |
| 306 del dependency_interface.extended_attributes['ImplementedAs'] | |
| 307 except KeyError: | |
| 308 pass | |
| 296 | 309 |
| 297 def update_attributes(attributes, extras): | 310 def update_attributes(attributes, extras): |
| 298 for key, value in extras.items(): | 311 for key, value in extras.items(): |
| 299 if key not in attributes: | 312 if key not in attributes: |
| 300 attributes[key] = value | 313 attributes[key] = value |
| 301 | 314 |
| 302 for attribute in dependency_interface.attributes: | 315 for attribute in dependency_interface.attributes: |
| 303 update_attributes(attribute.extended_attributes, merged_extended_attribu tes) | 316 update_attributes(attribute.extended_attributes, merged_extended_attribu tes) |
| 304 for constant in dependency_interface.constants: | 317 for constant in dependency_interface.constants: |
| 305 update_attributes(constant.extended_attributes, merged_extended_attribut es) | 318 update_attributes(constant.extended_attributes, merged_extended_attribut es) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 # This loop may process the same interface many times, so it's | 350 # This loop may process the same interface many times, so it's |
| 338 # possible that we're adding the same attributes twice or more. | 351 # possible that we're adding the same attributes twice or more. |
| 339 # So check if there is a duplicate. | 352 # So check if there is a duplicate. |
| 340 for attr in inherited_unforgeable_attributes: | 353 for attr in inherited_unforgeable_attributes: |
| 341 if attr not in interface.attributes: | 354 if attr not in interface.attributes: |
| 342 interface.attributes.append(attr) | 355 interface.attributes.append(attr) |
| 343 referenced_interfaces.extend(interface_info.get('referenced_interfac es', [])) | 356 referenced_interfaces.extend(interface_info.get('referenced_interfac es', [])) |
| 344 interface_info['referenced_interfaces'] = sorted(set(referenced_inte rfaces)) | 357 interface_info['referenced_interfaces'] = sorted(set(referenced_inte rfaces)) |
| 345 merge_dict_recursively(interface_info, | 358 merge_dict_recursively(interface_info, |
| 346 {'cpp_includes': {component: cpp_includes}}) | 359 {'cpp_includes': {component: cpp_includes}}) |
| OLD | NEW |