Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 # coding=utf-8 | 2 # coding=utf-8 |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 'wtf/GetPtr.h', | 70 'wtf/GetPtr.h', |
| 71 'wtf/RefPtr.h', | 71 'wtf/RefPtr.h', |
| 72 ]) | 72 ]) |
| 73 | 73 |
| 74 | 74 |
| 75 def interface_context(interface): | 75 def interface_context(interface): |
| 76 includes.clear() | 76 includes.clear() |
| 77 includes.update(INTERFACE_CPP_INCLUDES) | 77 includes.update(INTERFACE_CPP_INCLUDES) |
| 78 header_includes = set(INTERFACE_H_INCLUDES) | 78 header_includes = set(INTERFACE_H_INCLUDES) |
| 79 | 79 |
| 80 parent_interface = interface.parent | 80 if interface.is_partial: |
| 81 if parent_interface: | 81 # A partial interface definition cannot specify that the interface |
| 82 header_includes.update(v8_types.includes_for_interface(parent_interface) ) | 82 # inherits from another interface. Inheritance must be specified on |
| 83 # the original interface definition. | |
| 84 parent_interface = None | |
| 85 is_document = False | |
| 86 is_event_target = False | |
| 87 # partial interface needs the definition of its original interface. | |
| 88 includes.add('bindings/core/v8/V8%s.h' % interface.name) | |
| 89 else: | |
| 90 parent_interface = interface.parent | |
| 91 if parent_interface: | |
| 92 header_includes.update(v8_types.includes_for_interface(parent_interf ace)) | |
| 93 is_document = inherits_interface(interface.name, 'Document') | |
| 94 is_event_target = inherits_interface(interface.name, 'EventTarget') | |
| 95 | |
| 83 extended_attributes = interface.extended_attributes | 96 extended_attributes = interface.extended_attributes |
| 84 | 97 |
| 85 # [ActiveDOMObject] | 98 # [ActiveDOMObject] |
| 86 is_active_dom_object = 'ActiveDOMObject' in extended_attributes | 99 is_active_dom_object = 'ActiveDOMObject' in extended_attributes |
| 87 | 100 |
| 88 # [CheckSecurity] | 101 # [CheckSecurity] |
| 89 is_check_security = 'CheckSecurity' in extended_attributes | 102 is_check_security = 'CheckSecurity' in extended_attributes |
| 90 if is_check_security: | 103 if is_check_security: |
| 91 includes.add('bindings/core/v8/BindingSecurity.h') | 104 includes.add('bindings/core/v8/BindingSecurity.h') |
| 92 | 105 |
| 93 # [DependentLifetime] | 106 # [DependentLifetime] |
| 94 is_dependent_lifetime = 'DependentLifetime' in extended_attributes | 107 is_dependent_lifetime = 'DependentLifetime' in extended_attributes |
| 95 | 108 |
| 96 # [Iterable] | 109 # [Iterable] |
| 97 iterator_method = None | 110 iterator_method = None |
| 98 if 'Iterable' in extended_attributes: | 111 # FIXME: support Iterable in partial interfaces. However, we don't |
| 112 # need to support iterator overloads between interface and | |
| 113 # partial interface definitions. | |
| 114 # http://heycam.github.io/webidl/#idl-overloading | |
| 115 if 'Iterable' in extended_attributes and not interface.is_partial: | |
| 99 iterator_operation = IdlOperation(interface.idl_name) | 116 iterator_operation = IdlOperation(interface.idl_name) |
| 100 iterator_operation.name = 'iterator' | 117 iterator_operation.name = 'iterator' |
| 101 iterator_operation.idl_type = IdlType('Iterator') | 118 iterator_operation.idl_type = IdlType('Iterator') |
| 102 iterator_operation.extended_attributes['RaisesException'] = None | 119 iterator_operation.extended_attributes['RaisesException'] = None |
| 103 iterator_operation.extended_attributes['CallWith'] = 'ScriptState' | 120 iterator_operation.extended_attributes['CallWith'] = 'ScriptState' |
| 104 iterator_method = v8_methods.method_context(interface, | 121 iterator_method = v8_methods.method_context(interface, |
| 105 iterator_operation) | 122 iterator_operation) |
| 106 | 123 |
| 107 # [MeasureAs] | 124 # [MeasureAs] |
| 108 is_measure_as = 'MeasureAs' in extended_attributes | 125 is_measure_as = 'MeasureAs' in extended_attributes |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 135 # [Custom=Wrap], [SetWrapperReferenceFrom] | 152 # [Custom=Wrap], [SetWrapperReferenceFrom] |
| 136 has_visit_dom_wrapper = ( | 153 has_visit_dom_wrapper = ( |
| 137 has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or | 154 has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or |
| 138 reachable_node_function or | 155 reachable_node_function or |
| 139 set_wrapper_reference_to_list) | 156 set_wrapper_reference_to_list) |
| 140 | 157 |
| 141 this_gc_type = gc_type(interface) | 158 this_gc_type = gc_type(interface) |
| 142 | 159 |
| 143 wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Nod e') else 'ObjectClassId') | 160 wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Nod e') else 'ObjectClassId') |
| 144 | 161 |
| 162 v8_class_name = v8_utilities.v8_class_name(interface) | |
| 163 cpp_class_name = cpp_name(interface) | |
| 164 | |
| 145 context = { | 165 context = { |
| 166 'actual_cpp_class': cpp_class_name + 'Partial' if interface.is_partial e lse cpp_class_name, | |
| 167 'actual_v8_class': v8_class_name + 'Partial' if interface.is_partial els e v8_class_name, | |
|
haraken
2014/10/16 04:24:08
"actual_" wouldn't be a good name...
I don't have
tasak
2014/10/17 07:38:18
actual_ => _or_partial
| |
| 146 'conditional_string': conditional_string(interface), # [Conditional] | 168 'conditional_string': conditional_string(interface), # [Conditional] |
| 147 'cpp_class': cpp_name(interface), | 169 'cpp_class': cpp_class_name, |
| 148 'gc_type': this_gc_type, | 170 'gc_type': this_gc_type, |
| 149 # FIXME: Remove 'EventTarget' special handling, http://crbug.com/383699 | 171 # FIXME: Remove 'EventTarget' special handling, http://crbug.com/383699 |
| 150 'has_access_check_callbacks': (is_check_security and | 172 'has_access_check_callbacks': (is_check_security and |
| 151 interface.name != 'Window' and | 173 interface.name != 'Window' and |
| 152 interface.name != 'EventTarget'), | 174 interface.name != 'EventTarget'), |
| 153 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] | 175 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] |
| 154 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'T oV8'), # [Custom=ToV8] | 176 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'T oV8'), # [Custom=ToV8] |
| 155 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wr ap'), # [Custom=Wrap] | 177 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wr ap'), # [Custom=Wrap] |
| 178 'has_partial_interface': len(interface.partial_interfaces) > 0, | |
| 156 'has_visit_dom_wrapper': has_visit_dom_wrapper, | 179 'has_visit_dom_wrapper': has_visit_dom_wrapper, |
| 157 'header_includes': header_includes, | 180 'header_includes': header_includes, |
| 158 'interface_name': interface.name, | 181 'interface_name': interface.name, |
| 159 'is_active_dom_object': is_active_dom_object, | 182 'is_active_dom_object': is_active_dom_object, |
| 160 'is_check_security': is_check_security, | 183 'is_check_security': is_check_security, |
| 161 'is_dependent_lifetime': is_dependent_lifetime, | 184 'is_dependent_lifetime': is_dependent_lifetime, |
| 162 'is_event_target': inherits_interface(interface.name, 'EventTarget'), | 185 'is_document': is_document, |
| 186 'is_event_target': is_event_target, | |
| 163 'is_exception': interface.is_exception, | 187 'is_exception': interface.is_exception, |
| 164 'is_node': inherits_interface(interface.name, 'Node'), | 188 'is_node': inherits_interface(interface.name, 'Node'), |
| 189 'is_partial': interface.is_partial, | |
| 165 'is_script_wrappable': is_script_wrappable, | 190 'is_script_wrappable': is_script_wrappable, |
| 166 'iterator_method': iterator_method, | 191 'iterator_method': iterator_method, |
| 167 'lifetime': 'Dependent' | 192 'lifetime': 'Dependent' |
| 168 if (has_visit_dom_wrapper or | 193 if (has_visit_dom_wrapper or |
| 169 is_active_dom_object or | 194 is_active_dom_object or |
| 170 is_dependent_lifetime) | 195 is_dependent_lifetime) |
| 171 else 'Independent', | 196 else 'Independent', |
| 172 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs] | 197 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs] |
| 173 'parent_interface': parent_interface, | 198 'parent_interface': parent_interface, |
| 174 'pass_cpp_type': cpp_template_type( | 199 'pass_cpp_type': cpp_template_type( |
| 175 cpp_ptr_type('PassRefPtr', 'RawPtr', this_gc_type), | 200 cpp_ptr_type('PassRefPtr', 'RawPtr', this_gc_type), |
| 176 cpp_name(interface)), | 201 cpp_name(interface)), |
| 177 'reachable_node_function': reachable_node_function, | 202 'reachable_node_function': reachable_node_function, |
| 178 'runtime_enabled_function': runtime_enabled_function_name(interface), # [RuntimeEnabled] | 203 'runtime_enabled_function': runtime_enabled_function_name(interface), # [RuntimeEnabled] |
| 179 'set_wrapper_reference_to_list': set_wrapper_reference_to_list, | 204 'set_wrapper_reference_to_list': set_wrapper_reference_to_list, |
| 180 'v8_class': v8_utilities.v8_class_name(interface), | 205 'v8_class': v8_class_name, |
| 181 'wrapper_class_id': wrapper_class_id, | 206 'wrapper_class_id': wrapper_class_id, |
| 182 } | 207 } |
| 183 | 208 |
| 184 # Constructors | 209 # Constructors |
| 185 constructors = [constructor_context(interface, constructor) | 210 constructors = [constructor_context(interface, constructor) |
| 186 for constructor in interface.constructors | 211 for constructor in interface.constructors |
| 187 # FIXME: shouldn't put named constructors with constructors | 212 # FIXME: shouldn't put named constructors with constructors |
| 188 # (currently needed for Perl compatibility) | 213 # (currently needed for Perl compatibility) |
| 189 # Handle named constructors separately | 214 # Handle named constructors separately |
| 190 if constructor.name == 'Constructor'] | 215 if constructor.name == 'Constructor'] |
| 191 if len(constructors) > 1: | 216 if len(constructors) > 1: |
| 192 context['constructor_overloads'] = overloads_context(constructors) | 217 context['constructor_overloads'] = overloads_context(interface, construc tors) |
| 193 | 218 |
| 194 # [CustomConstructor] | 219 # [CustomConstructor] |
| 195 custom_constructors = [{ # Only needed for computing interface length | 220 custom_constructors = [{ # Only needed for computing interface length |
| 196 'number_of_required_arguments': | 221 'number_of_required_arguments': |
| 197 number_of_required_arguments(constructor), | 222 number_of_required_arguments(constructor), |
| 198 } for constructor in interface.custom_constructors] | 223 } for constructor in interface.custom_constructors] |
| 199 | 224 |
| 200 # [EventConstructor] | 225 # [EventConstructor] |
| 201 has_event_constructor = 'EventConstructor' in extended_attributes | 226 has_event_constructor = 'EventConstructor' in interface.extended_attributes |
| 227 # [NamedConstructor] | |
| 228 named_constructor = named_constructor_context(interface) | |
| 229 | |
| 230 if constructors or custom_constructors or has_event_constructor or named_con structor: | |
| 231 if interface.is_partial: | |
| 232 raise Exception('[Constructor] and [NamedConstructor] MUST NOT be' | |
| 233 ' specified on partial interface definitions:' | |
| 234 '%s' % interface.name) | |
| 235 | |
| 236 includes.add('bindings/core/v8/V8ObjectConstructor.h') | |
| 237 includes.add('core/frame/LocalDOMWindow.h') | |
| 238 | |
| 202 any_type_attributes = [attribute for attribute in interface.attributes | 239 any_type_attributes = [attribute for attribute in interface.attributes |
| 203 if attribute.idl_type.name == 'Any'] | 240 if attribute.idl_type.name == 'Any'] |
| 204 if has_event_constructor: | 241 if has_event_constructor: |
| 205 includes.add('bindings/core/v8/Dictionary.h') | 242 includes.add('bindings/core/v8/Dictionary.h') |
| 206 if any_type_attributes: | 243 if any_type_attributes: |
| 207 includes.add('bindings/core/v8/SerializedScriptValue.h') | 244 includes.add('bindings/core/v8/SerializedScriptValue.h') |
| 208 | 245 |
| 209 # [NamedConstructor] | |
| 210 named_constructor = named_constructor_context(interface) | |
| 211 | |
| 212 if (constructors or custom_constructors or has_event_constructor or | |
| 213 named_constructor): | |
| 214 includes.add('bindings/core/v8/V8ObjectConstructor.h') | |
| 215 includes.add('core/frame/LocalDOMWindow.h') | |
| 216 | |
| 217 context.update({ | 246 context.update({ |
| 218 'any_type_attributes': any_type_attributes, | 247 'any_type_attributes': any_type_attributes, |
| 219 'constructors': constructors, | 248 'constructors': constructors, |
| 220 'has_custom_constructor': bool(custom_constructors), | 249 'has_custom_constructor': bool(custom_constructors), |
| 221 'has_event_constructor': has_event_constructor, | 250 'has_event_constructor': has_event_constructor, |
| 222 'interface_length': | 251 'interface_length': |
| 223 interface_length(interface, constructors + custom_constructors), | 252 interface_length(interface, constructors + custom_constructors), |
| 224 'is_constructor_raises_exception': extended_attributes.get('RaisesExcept ion') == 'Constructor', # [RaisesException=Constructor] | 253 'is_constructor_raises_exception': |
| 254 interface.extended_attributes.get('RaisesException') == 'Constructor ', # [RaisesException=Constructor] | |
| 225 'named_constructor': named_constructor, | 255 'named_constructor': named_constructor, |
| 226 }) | 256 }) |
| 227 | 257 |
| 228 constants = [constant_context(constant) for constant in interface.constants] | 258 constants = [constant_context(constant) for constant in interface.constants] |
| 229 | 259 |
| 230 special_getter_constants = [] | 260 special_getter_constants = [] |
| 231 runtime_enabled_constants = [] | 261 runtime_enabled_constants = [] |
| 232 constant_configuration_constants = [] | 262 constant_configuration_constants = [] |
| 233 | 263 |
| 234 for constant in constants: | 264 for constant in constants: |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 264 attribute['runtime_enabled_function'] or | 294 attribute['runtime_enabled_function'] or |
| 265 attribute['per_context_enabled_function']) | 295 attribute['per_context_enabled_function']) |
| 266 and attribute['should_be_exposed_to_script'] | 296 and attribute['should_be_exposed_to_script'] |
| 267 for attribute in attributes), | 297 for attribute in attributes), |
| 268 'has_conditional_attributes': any(attribute['per_context_enabled_functio n'] or attribute['exposed_test'] for attribute in attributes), | 298 'has_conditional_attributes': any(attribute['per_context_enabled_functio n'] or attribute['exposed_test'] for attribute in attributes), |
| 269 'has_constructor_attributes': any(attribute['constructor_type'] for attr ibute in attributes), | 299 'has_constructor_attributes': any(attribute['constructor_type'] for attr ibute in attributes), |
| 270 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib ute in attributes), | 300 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib ute in attributes), |
| 271 }) | 301 }) |
| 272 | 302 |
| 273 # Methods | 303 # Methods |
| 274 methods = [v8_methods.method_context(interface, method) | 304 methods = [] |
| 275 for method in interface.operations | 305 if interface.original_interface: |
| 276 if method.name] # Skip anonymous special operations (methods) | 306 methods.extend([v8_methods.method_context(interface, operation, is_visib le=False) |
| 277 compute_method_overloads_context(methods) | 307 for operation in interface.original_interface.operations |
| 308 if operation.name]) | |
| 309 methods.extend([v8_methods.method_context(interface, method) | |
| 310 for method in interface.operations | |
| 311 if method.name]) # Skip anonymous special operations (metho ds) | |
| 312 if interface.partial_interfaces: | |
| 313 assert len(interface.partial_interfaces) == len(set(interface.partial_in terfaces)) | |
| 314 for partial_interface in interface.partial_interfaces: | |
| 315 methods.extend([v8_methods.method_context(interface, operation, is_v isible=False) | |
| 316 for operation in partial_interface.operations | |
| 317 if operation.name]) | |
| 318 compute_method_overloads_context(interface, methods) | |
| 278 | 319 |
| 279 # Stringifier | 320 # Stringifier |
| 280 if interface.stringifier: | 321 if interface.stringifier: |
| 281 stringifier = interface.stringifier | 322 stringifier = interface.stringifier |
| 282 method = IdlOperation(interface.idl_name) | 323 method = IdlOperation(interface.idl_name) |
| 283 method.name = 'toString' | 324 method.name = 'toString' |
| 284 method.idl_type = IdlType('DOMString') | 325 method.idl_type = IdlType('DOMString') |
| 285 method.extended_attributes.update(stringifier.extended_attributes) | 326 method.extended_attributes.update(stringifier.extended_attributes) |
| 286 if stringifier.attribute: | 327 if stringifier.attribute: |
| 287 method.extended_attributes['ImplementedAs'] = stringifier.attribute. name | 328 method.extended_attributes['ImplementedAs'] = stringifier.attribute. name |
| 288 elif stringifier.operation: | 329 elif stringifier.operation: |
| 289 method.extended_attributes['ImplementedAs'] = stringifier.operation. name | 330 method.extended_attributes['ImplementedAs'] = stringifier.operation. name |
| 290 methods.append(v8_methods.method_context(interface, method)) | 331 methods.append(v8_methods.method_context(interface, method)) |
| 291 | 332 |
| 292 conditionally_enabled_methods = [] | 333 conditionally_enabled_methods = [] |
| 293 custom_registration_methods = [] | 334 custom_registration_methods = [] |
| 294 method_configuration_methods = [] | 335 method_configuration_methods = [] |
| 295 | 336 |
| 296 for method in methods: | 337 for method in methods: |
| 297 # Skip all but one method in each set of overloaded methods. | 338 # Skip all but one method in each set of overloaded methods. |
| 298 if 'overload_index' in method and 'overloads' not in method: | 339 if 'overload_index' in method and 'overloads' not in method: |
| 299 continue | 340 continue |
| 300 | 341 |
| 301 if 'overloads' in method: | 342 if 'overloads' in method: |
| 302 overloads = method['overloads'] | 343 overloads = method['overloads'] |
| 344 if not overloads['visible']: | |
| 345 continue | |
| 346 # original interface will register instead of partial interface. | |
| 347 if overloads['has_partial_overloads'] and interface.is_partial: | |
| 348 continue | |
| 303 per_context_enabled_function = overloads['per_context_enabled_functi on_all'] | 349 per_context_enabled_function = overloads['per_context_enabled_functi on_all'] |
| 304 conditionally_exposed_function = overloads['exposed_test_all'] | 350 conditionally_exposed_function = overloads['exposed_test_all'] |
| 305 runtime_enabled_function = overloads['runtime_enabled_function_all'] | 351 runtime_enabled_function = overloads['runtime_enabled_function_all'] |
| 306 has_custom_registration = overloads['has_custom_registration_all'] | 352 has_custom_registration = overloads['has_custom_registration_all'] |
| 307 else: | 353 else: |
| 354 if not method['visible']: | |
| 355 continue | |
| 308 per_context_enabled_function = method['per_context_enabled_function' ] | 356 per_context_enabled_function = method['per_context_enabled_function' ] |
| 309 conditionally_exposed_function = method['exposed_test'] | 357 conditionally_exposed_function = method['exposed_test'] |
| 310 runtime_enabled_function = method['runtime_enabled_function'] | 358 runtime_enabled_function = method['runtime_enabled_function'] |
| 311 has_custom_registration = method['has_custom_registration'] | 359 has_custom_registration = method['has_custom_registration'] |
| 312 | 360 |
| 313 if per_context_enabled_function or conditionally_exposed_function: | 361 if per_context_enabled_function or conditionally_exposed_function: |
| 314 conditionally_enabled_methods.append(method) | 362 conditionally_enabled_methods.append(method) |
| 315 continue | 363 continue |
| 316 if runtime_enabled_function or has_custom_registration: | 364 if runtime_enabled_function or has_custom_registration: |
| 317 custom_registration_methods.append(method) | 365 custom_registration_methods.append(method) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 'reflected_name': extended_attributes.get('Reflect', constant.name), | 420 'reflected_name': extended_attributes.get('Reflect', constant.name), |
| 373 'runtime_enabled_function': runtime_enabled_function_name(constant), | 421 'runtime_enabled_function': runtime_enabled_function_name(constant), |
| 374 'value': constant.value, | 422 'value': constant.value, |
| 375 } | 423 } |
| 376 | 424 |
| 377 | 425 |
| 378 ################################################################################ | 426 ################################################################################ |
| 379 # Overloads | 427 # Overloads |
| 380 ################################################################################ | 428 ################################################################################ |
| 381 | 429 |
| 382 def compute_method_overloads_context(methods): | 430 def compute_method_overloads_context(interface, methods): |
| 383 # Regular methods | 431 # Regular methods |
| 384 compute_method_overloads_context_by_type([method for method in methods | 432 compute_method_overloads_context_by_type( |
| 385 if not method['is_static']]) | 433 interface, [method for method in methods if not method['is_static']]) |
| 386 # Static methods | 434 # Static methods |
| 387 compute_method_overloads_context_by_type([method for method in methods | 435 compute_method_overloads_context_by_type( |
| 388 if method['is_static']]) | 436 interface, [method for method in methods if method['is_static']]) |
| 389 | 437 |
| 390 | 438 |
| 391 def compute_method_overloads_context_by_type(methods): | 439 def compute_method_overloads_context_by_type(interface, methods): |
| 392 """Computes |method.overload*| template values. | 440 """Computes |method.overload*| template values. |
| 393 | 441 |
| 394 Called separately for static and non-static (regular) methods, | 442 Called separately for static and non-static (regular) methods, |
| 395 as these are overloaded separately. | 443 as these are overloaded separately. |
| 396 Modifies |method| in place for |method| in |methods|. | 444 Modifies |method| in place for |method| in |methods|. |
| 397 Doesn't change the |methods| list itself (only the values, i.e. individual | 445 Doesn't change the |methods| list itself (only the values, i.e. individual |
| 398 methods), so ok to treat these separately. | 446 methods), so ok to treat these separately. |
| 399 """ | 447 """ |
| 400 # Add overload information only to overloaded methods, so template code can | 448 # Add overload information only to overloaded methods, so template code can |
| 401 # easily verify if a function is overloaded | 449 # easily verify if a function is overloaded |
| 402 for name, overloads in method_overloads_by_name(methods): | 450 for name, overloads in method_overloads_by_name(methods): |
| 403 # Resolution function is generated after last overloaded function; | 451 # Resolution function is generated after last overloaded function; |
| 404 # package necessary information into |method.overloads| for that method. | 452 # package necessary information into |method.overloads| for that method. |
| 405 overloads[-1]['overloads'] = overloads_context(overloads) | 453 overloads[-1]['overloads'] = overloads_context(interface, overloads) |
| 406 overloads[-1]['overloads']['name'] = name | 454 overloads[-1]['overloads']['name'] = name |
| 407 | 455 |
| 408 | 456 |
| 409 def method_overloads_by_name(methods): | 457 def method_overloads_by_name(methods): |
| 410 """Returns generator of overloaded methods by name: [name, [method]]""" | 458 """Returns generator of overloaded methods by name: [name, [method]]""" |
| 411 # Filter to only methods that are actually overloaded | 459 # Filter to only methods that are actually overloaded |
| 412 method_counts = Counter(method['name'] for method in methods) | 460 method_counts = Counter(method['name'] for method in methods) |
| 413 overloaded_method_names = set(name | 461 overloaded_method_names = set(name |
| 414 for name, count in method_counts.iteritems() | 462 for name, count in method_counts.iteritems() |
| 415 if count > 1) | 463 if count > 1) |
| 416 overloaded_methods = [method for method in methods | 464 overloaded_methods = [method for method in methods |
| 417 if method['name'] in overloaded_method_names] | 465 if method['name'] in overloaded_method_names] |
| 418 | 466 |
| 419 # Group by name (generally will be defined together, but not necessarily) | 467 # Group by name (generally will be defined together, but not necessarily) |
| 420 return sort_and_groupby(overloaded_methods, itemgetter('name')) | 468 return sort_and_groupby(overloaded_methods, itemgetter('name')) |
| 421 | 469 |
| 422 | 470 |
| 423 def overloads_context(overloads): | 471 def overloads_context(interface, overloads): |
| 424 """Returns |overloads| template values for a single name. | 472 """Returns |overloads| template values for a single name. |
| 425 | 473 |
| 426 Sets |method.overload_index| in place for |method| in |overloads| | 474 Sets |method.overload_index| in place for |method| in |overloads| |
| 427 and returns dict of overall overload template values. | 475 and returns dict of overall overload template values. |
| 428 """ | 476 """ |
| 429 assert len(overloads) > 1 # only apply to overloaded names | 477 assert len(overloads) > 1 # only apply to overloaded names |
| 430 for index, method in enumerate(overloads, 1): | 478 for index, method in enumerate(overloads, 1): |
| 431 method['overload_index'] = index | 479 method['overload_index'] = index |
| 432 | 480 |
| 433 effective_overloads_by_length = effective_overload_set_by_length(overloads) | 481 effective_overloads_by_length = effective_overload_set_by_length(overloads) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 459 raise ValueError('Overloads of %s have conflicting extended attr ibute %s' | 507 raise ValueError('Overloads of %s have conflicting extended attr ibute %s' |
| 460 % (name, extended_attribute)) | 508 % (name, extended_attribute)) |
| 461 | 509 |
| 462 # Check and fail if overloads disagree about whether the return type | 510 # Check and fail if overloads disagree about whether the return type |
| 463 # is a Promise or not. | 511 # is a Promise or not. |
| 464 promise_overload_count = sum(1 for method in overloads if method.get('idl_ty pe') == 'Promise') | 512 promise_overload_count = sum(1 for method in overloads if method.get('idl_ty pe') == 'Promise') |
| 465 if promise_overload_count not in (0, len(overloads)): | 513 if promise_overload_count not in (0, len(overloads)): |
| 466 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes' | 514 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes' |
| 467 % (name)) | 515 % (name)) |
| 468 | 516 |
| 517 overloads_visibles = set([method.get('visible', True) for method in overload s]) | |
| 518 if len(overloads_visibles) > 1: | |
| 519 overloads_visible = True | |
| 520 has_partial_overloads = True | |
| 521 else: | |
| 522 overloads_visible = overloads_visibles.pop() | |
| 523 has_partial_overloads = False | |
|
haraken
2014/10/16 04:24:08
Discussed offline and I understood what this code
tasak
2014/10/17 07:38:18
Done.
| |
| 524 | |
| 469 return { | 525 return { |
| 470 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs] | 526 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs] |
| 471 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ] | 527 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ] |
| 472 'has_custom_registration_all': common_value(overloads, 'has_custom_regis tration'), | 528 'has_custom_registration_all': common_value(overloads, 'has_custom_regis tration'), |
| 473 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), | 529 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), |
| 474 # 1. Let maxarg be the length of the longest type list of the | 530 # 1. Let maxarg be the length of the longest type list of the |
| 475 # entries in S. | 531 # entries in S. |
| 476 'maxarg': lengths[-1], | 532 'maxarg': lengths[-1], |
| 477 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] | 533 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] |
| 478 'minarg': lengths[0], | 534 'minarg': lengths[0], |
| 479 'per_context_enabled_function_all': common_value(overloads, 'per_context _enabled_function'), # [PerContextEnabled] | 535 'per_context_enabled_function_all': common_value(overloads, 'per_context _enabled_function'), # [PerContextEnabled] |
| 480 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled _function'), # [RuntimeEnabled] | 536 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled _function'), # [RuntimeEnabled] |
| 481 'valid_arities': lengths | 537 'valid_arities': lengths |
| 482 # Only need to report valid arities if there is a gap in the | 538 # Only need to report valid arities if there is a gap in the |
| 483 # sequence of possible lengths, otherwise invalid length means | 539 # sequence of possible lengths, otherwise invalid length means |
| 484 # "not enough arguments". | 540 # "not enough arguments". |
| 485 if lengths[-1] - lengths[0] != len(lengths) - 1 else None, | 541 if lengths[-1] - lengths[0] != len(lengths) - 1 else None, |
| 542 'visible': overloads_visible, | |
| 543 'has_partial_overloads': has_partial_overloads, | |
| 486 } | 544 } |
| 487 | 545 |
| 488 | 546 |
| 489 def effective_overload_set(F): | 547 def effective_overload_set(F): |
| 490 """Returns the effective overload set of an overloaded function. | 548 """Returns the effective overload set of an overloaded function. |
| 491 | 549 |
| 492 An effective overload set is the set of overloaded functions + signatures | 550 An effective overload set is the set of overloaded functions + signatures |
| 493 (type list of arguments, with optional and variadic arguments included or | 551 (type list of arguments, with optional and variadic arguments included or |
| 494 not), and is used in the overload resolution algorithm. | 552 not), and is used in the overload resolution algorithm. |
| 495 | 553 |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1133 deleter = next( | 1191 deleter = next( |
| 1134 method | 1192 method |
| 1135 for method in interface.operations | 1193 for method in interface.operations |
| 1136 if ('deleter' in method.specials and | 1194 if ('deleter' in method.specials and |
| 1137 len(method.arguments) == 1 and | 1195 len(method.arguments) == 1 and |
| 1138 str(method.arguments[0].idl_type) == 'DOMString')) | 1196 str(method.arguments[0].idl_type) == 'DOMString')) |
| 1139 except StopIteration: | 1197 except StopIteration: |
| 1140 return None | 1198 return None |
| 1141 | 1199 |
| 1142 return property_deleter(deleter) | 1200 return property_deleter(deleter) |
| OLD | NEW |