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 16 matching lines...) Expand all Loading... |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 """Generate template values for an interface. | 29 """Generate template values for an interface. |
30 | 30 |
31 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 31 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
32 """ | 32 """ |
33 | 33 |
34 from collections import defaultdict | 34 from collections import defaultdict |
35 | 35 |
36 import idl_types | 36 import idl_types |
37 from idl_types import IdlType, inherits_interface | 37 from idl_types import IdlType, inherits_interface, IdlArrayOrSequenceType, IdlAr
rayType |
38 import dart_attributes | 38 import dart_attributes |
39 import dart_methods | 39 import dart_methods |
40 import dart_types | 40 import dart_types |
41 from dart_utilities import DartUtilities | 41 from dart_utilities import DartUtilities |
42 from v8_globals import includes | 42 from v8_globals import includes |
43 | 43 |
44 | 44 |
45 INTERFACE_H_INCLUDES = frozenset([ | 45 INTERFACE_H_INCLUDES = frozenset([ |
46 'bindings/dart/DartDOMWrapper.h', | 46 'bindings/core/dart/DartDOMWrapper.h', |
47 'platform/heap/Handle.h', | 47 'platform/heap/Handle.h', |
48 ]) | 48 ]) |
49 | 49 |
50 INTERFACE_CPP_INCLUDES = frozenset([ | 50 INTERFACE_CPP_INCLUDES = frozenset([ |
51 'DartUtilities.h', | 51 |
| 52 'bindings/core/dart/DartUtilities.h', |
52 'wtf/GetPtr.h', | 53 'wtf/GetPtr.h', |
53 'wtf/RefPtr.h', | 54 'wtf/RefPtr.h', |
54 ]) | 55 ]) |
55 | 56 |
56 | 57 |
57 # TODO(terry): Temporary to not generate a method, getter/setter. Format is: | 58 # TODO(terry): Temporary to not generate a method, getter/setter. Format is: |
58 # | 59 # |
59 # interface_name.method_name | 60 # interface_name.method_name |
60 # interface_name.get:attribute_name | 61 # interface_name.get:attribute_name |
61 # interface_name.set:attribute_name | 62 # interface_name.set:attribute_name |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 # FIXME(vsm): We probably need bindings/dart/DartController and | 429 # FIXME(vsm): We probably need bindings/dart/DartController and |
429 # core/frame/LocalFrame.h here. | 430 # core/frame/LocalFrame.h here. |
430 includes.update(['DartDocument.h']) | 431 includes.update(['DartDocument.h']) |
431 | 432 |
432 if inherits_interface(interface.name, 'DataTransferItemList'): | 433 if inherits_interface(interface.name, 'DataTransferItemList'): |
433 # FIXME(jacobr): this is a hack. | 434 # FIXME(jacobr): this is a hack. |
434 includes.update(['core/html/HTMLCollection.h']) | 435 includes.update(['core/html/HTMLCollection.h']) |
435 | 436 |
436 | 437 |
437 if inherits_interface(interface.name, 'EventTarget'): | 438 if inherits_interface(interface.name, 'EventTarget'): |
438 includes.update(['DartEventListener.h']) | 439 includes.update(['bindings/core/dart/DartEventListener.h']) |
439 | 440 |
440 # [ActiveDOMObject] | 441 # [ActiveDOMObject] |
441 is_active_dom_object = 'ActiveDOMObject' in extended_attributes | 442 is_active_dom_object = 'ActiveDOMObject' in extended_attributes |
442 | 443 |
443 # [CheckSecurity] | 444 # [CheckSecurity] |
444 is_check_security = 'CheckSecurity' in extended_attributes | 445 is_check_security = 'CheckSecurity' in extended_attributes |
445 if is_check_security: | 446 if is_check_security: |
446 includes.add('bindings/common/BindingSecurity.h') | 447 includes.add('bindings/common/BindingSecurity.h') |
447 | 448 |
448 # [DependentLifetime] | 449 # [DependentLifetime] |
449 is_dependent_lifetime = 'DependentLifetime' in extended_attributes | 450 is_dependent_lifetime = 'DependentLifetime' in extended_attributes |
450 | 451 |
451 # [MeasureAs] | 452 # [MeasureAs] |
452 # TODO(terry): Remove Me? | 453 # TODO(terry): Remove Me? |
453 # is_measure_as = 'MeasureAs' in extended_attributes | 454 # is_measure_as = 'MeasureAs' in extended_attributes |
454 # if is_measure_as: | 455 # if is_measure_as: |
455 # includes.add('core/frame/UseCounter.h') | 456 # includes.add('core/frame/UseCounter.h') |
456 | 457 |
457 # [SetWrapperReferenceFrom] | 458 # [SetWrapperReferenceFrom] |
458 reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom') | 459 reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom') |
459 if reachable_node_function: | 460 if reachable_node_function: |
460 # FIXME(vsm): We may need bindings/dart/DartGCController.h instead. | 461 # FIXME(vsm): We may need bindings/dart/DartGCController.h instead. |
461 includes.update(['bindings/v8/V8GCController.h', | 462 includes.update(['bindings/core/v8/V8GCController.h', |
462 'core/dom/Element.h']) | 463 'core/dom/Element.h']) |
463 | 464 |
464 # [SetWrapperReferenceTo] | 465 # [SetWrapperReferenceTo] |
465 set_wrapper_reference_to_list = [{ | 466 set_wrapper_reference_to_list = [{ |
466 'name': argument.name, | 467 'name': argument.name, |
467 # FIXME: properly should be: | 468 # FIXME: properly should be: |
468 # 'cpp_type': argument.idl_type.cpp_type_args(used_as_argument=True), | 469 # 'cpp_type': argument.idl_type.cpp_type_args(used_as_rvalue_type=True), |
469 # (if type is non-wrapper type like NodeFilter, normally RefPtr) | 470 # (if type is non-wrapper type like NodeFilter, normally RefPtr) |
470 # Raw pointers faster though, and NodeFilter hacky anyway. | 471 # Raw pointers faster though, and NodeFilter hacky anyway. |
471 'cpp_type': argument.idl_type.implemented_as + '*', | 472 'cpp_type': argument.idl_type.implemented_as + '*', |
472 'idl_type': argument.idl_type, | 473 'idl_type': argument.idl_type, |
473 'v8_type': dart_types.v8_type(argument.idl_type.name), | 474 'v8_type': dart_types.v8_type(argument.idl_type.name), |
474 } for argument in extended_attributes.get('SetWrapperReferenceTo', [])] | 475 } for argument in extended_attributes.get('SetWrapperReferenceTo', [])] |
475 for set_wrapper_reference_to in set_wrapper_reference_to_list: | 476 for set_wrapper_reference_to in set_wrapper_reference_to_list: |
476 set_wrapper_reference_to['idl_type'].add_includes_for_type() | 477 set_wrapper_reference_to['idl_type'].add_includes_for_type() |
477 | 478 |
478 # [SpecialWrapFor] | 479 # [SpecialWrapFor] |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 541 |
541 # [CustomConstructor] | 542 # [CustomConstructor] |
542 custom_constructors = [generate_custom_constructor(interface, constructor) | 543 custom_constructors = [generate_custom_constructor(interface, constructor) |
543 for constructor in interface.custom_constructors] | 544 for constructor in interface.custom_constructors] |
544 | 545 |
545 # [EventConstructor] | 546 # [EventConstructor] |
546 has_event_constructor = 'EventConstructor' in extended_attributes | 547 has_event_constructor = 'EventConstructor' in extended_attributes |
547 any_type_attributes = [attribute for attribute in interface.attributes | 548 any_type_attributes = [attribute for attribute in interface.attributes |
548 if attribute.idl_type.name == 'Any'] | 549 if attribute.idl_type.name == 'Any'] |
549 if has_event_constructor: | 550 if has_event_constructor: |
550 includes.add('bindings/common/Dictionary.h') | 551 includes.add('bindings/core/v8/Dictionary.h') |
551 if any_type_attributes: | 552 if any_type_attributes: |
552 includes.add('bindings/v8/SerializedScriptValue.h') | 553 includes.add('bindings/core/v8/SerializedScriptValue.h') |
553 | 554 |
554 # [NamedConstructor] | 555 # [NamedConstructor] |
555 named_constructor = generate_named_constructor(interface) | 556 named_constructor = generate_named_constructor(interface) |
556 | 557 |
557 add_native_entries(interface, constructors, bool(custom_constructors)) | 558 add_native_entries(interface, constructors, bool(custom_constructors)) |
558 add_native_entries(interface, custom_constructors, bool(custom_constructors)
) | 559 add_native_entries(interface, custom_constructors, bool(custom_constructors)
) |
559 if named_constructor: | 560 if named_constructor: |
560 add_native_entries(interface, [named_constructor], bool(custom_construct
ors)) | 561 add_native_entries(interface, [named_constructor], bool(custom_construct
ors)) |
561 | 562 |
562 if (constructors or custom_constructors or has_event_constructor or | 563 if (constructors or custom_constructors or has_event_constructor or |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 cpp_value = 'info[%s]' % index | 861 cpp_value = 'info[%s]' % index |
861 idl_type = argument['idl_type_object'] | 862 idl_type = argument['idl_type_object'] |
862 # FIXME(vsm): We need Dart specific checks for the rest of this method. | 863 # FIXME(vsm): We need Dart specific checks for the rest of this method. |
863 # FIXME: proper type checking, sharing code with attributes and methods | 864 # FIXME: proper type checking, sharing code with attributes and methods |
864 # FIXME(terry): DartStrictTypeChecking no longer supported; TypeChecking is | 865 # FIXME(terry): DartStrictTypeChecking no longer supported; TypeChecking is |
865 # new extended attribute. | 866 # new extended attribute. |
866 if idl_type.name == 'String' and argument['is_strict_type_checking']: | 867 if idl_type.name == 'String' and argument['is_strict_type_checking']: |
867 return ' || '.join(['isUndefinedOrNull(%s)' % cpp_value, | 868 return ' || '.join(['isUndefinedOrNull(%s)' % cpp_value, |
868 '%s->IsString()' % cpp_value, | 869 '%s->IsString()' % cpp_value, |
869 '%s->IsObject()' % cpp_value]) | 870 '%s->IsObject()' % cpp_value]) |
870 if idl_type.array_or_sequence_type: | 871 if idl_type.native_array_element_type: |
871 return '%s->IsArray()' % cpp_value | 872 return '%s->IsArray()' % cpp_value |
872 if idl_type.is_callback_interface: | 873 if idl_type.is_callback_interface: |
873 return ' || '.join(['%s->IsNull()' % cpp_value, | 874 return ' || '.join(['%s->IsNull()' % cpp_value, |
874 '%s->IsFunction()' % cpp_value]) | 875 '%s->IsFunction()' % cpp_value]) |
875 if idl_type.is_wrapper_type: | 876 if idl_type.is_wrapper_type: |
876 type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'
.format(idl_type=idl_type.base_type, cpp_value=cpp_value) | 877 type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'
.format(idl_type=idl_type.base_type, cpp_value=cpp_value) |
877 if idl_type.is_nullable: | 878 if idl_type.is_nullable: |
878 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) | 879 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) |
879 return type_check | 880 return type_check |
880 if idl_type.is_interface_type: | 881 if idl_type.is_interface_type: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 'number_of_arguments': len(constructor.arguments), | 941 'number_of_arguments': len(constructor.arguments), |
941 } | 942 } |
942 | 943 |
943 | 944 |
944 def constructor_argument_list(interface, constructor): | 945 def constructor_argument_list(interface, constructor): |
945 # FIXME: unify with dart_methods.cpp_argument. | 946 # FIXME: unify with dart_methods.cpp_argument. |
946 | 947 |
947 def cpp_argument(argument): | 948 def cpp_argument(argument): |
948 argument_name = dart_types.check_reserved_name(argument.name) | 949 argument_name = dart_types.check_reserved_name(argument.name) |
949 idl_type = argument.idl_type | 950 idl_type = argument.idl_type |
950 if idl_type.is_typed_array_type: | 951 # FIXMEDART: there has to be a cleaner way to check for arraylike |
| 952 # types such as Uint8ClampedArray. |
| 953 if isinstance(idl_type, IdlArrayType) or idl_type.preprocessed_type.is_t
yped_array_type: |
951 return '%s.get()' % argument_name | 954 return '%s.get()' % argument_name |
952 | 955 |
953 return argument_name | 956 return argument_name |
954 | 957 |
955 arguments = [] | 958 arguments = [] |
956 # [ConstructorCallWith=ExecutionContext] | 959 # [ConstructorCallWith=ExecutionContext] |
957 if DartUtilities.has_extended_attribute_value(interface, 'ConstructorCallWit
h', 'ExecutionContext'): | 960 if DartUtilities.has_extended_attribute_value(interface, 'ConstructorCallWit
h', 'ExecutionContext'): |
958 arguments.append('context') | 961 arguments.append('context') |
959 # [ConstructorCallWith=Document] | 962 # [ConstructorCallWith=Document] |
960 if DartUtilities.has_extended_attribute_value(interface, 'ConstructorCallWit
h', 'Document'): | 963 if DartUtilities.has_extended_attribute_value(interface, 'ConstructorCallWit
h', 'Document'): |
961 arguments.append('document') | 964 arguments.append('document') |
962 | 965 |
963 arguments.extend([cpp_argument(argument) for argument in constructor.argumen
ts]) | 966 arguments.extend([cpp_argument(argument) for argument in constructor.argumen
ts]) |
964 | 967 |
965 # [RaisesException=Constructor] | 968 # [RaisesException=Constructor] |
966 if interface.extended_attributes.get('RaisesException') == 'Constructor': | 969 if interface.extended_attributes.get('RaisesException') == 'Constructor': |
967 arguments.append('es') | 970 arguments.append('es') |
968 | 971 |
969 return arguments | 972 return arguments |
970 | 973 |
971 | 974 |
972 # TODO(terry): Eliminate this function use dart_methods.generate_argument instea
d | 975 # TODO(terry): Eliminate this function use dart_methods.generate_argument instea
d |
973 # for all constructor arguments. | 976 # for all constructor arguments. |
974 def constructor_argument(interface, argument, index): | 977 def constructor_argument(interface, argument, index): |
975 idl_type = argument.idl_type | 978 idl_type = argument.idl_type |
976 default_value = str(argument.default_value) if argument.default_value else N
one | 979 default_value = str(argument.default_value) if argument.default_value else N
one |
977 | 980 |
978 argument_content = { | 981 argument_content = { |
979 'cpp_type': idl_type.cpp_type_args(), | 982 'cpp_type': idl_type.cpp_type_args(), |
980 'local_cpp_type': idl_type.cpp_type_args(argument.extended_attributes, u
sed_as_argument=True), | 983 'local_cpp_type': idl_type.cpp_type_args(argument.extended_attributes, r
aw_type=True), |
981 # FIXME: check that the default value's type is compatible with the argu
ment's | 984 # FIXME: check that the default value's type is compatible with the argu
ment's |
982 'default_value': default_value, | 985 'default_value': default_value, |
983 # FIXME: remove once [Default] removed and just use argument.default_val
ue | 986 # FIXME: remove once [Default] removed and just use argument.default_val
ue |
984 'has_default': 'Default' in argument.extended_attributes or default_valu
e, | 987 'has_default': 'Default' in argument.extended_attributes or default_valu
e, |
985 'idl_type_object': idl_type, | 988 'idl_type_object': idl_type, |
986 'preprocessed_type': str(idl_type.preprocessed_type), | 989 'preprocessed_type': str(idl_type.preprocessed_type), |
987 # Dictionary is special-cased, but arrays and sequences shouldn't be | 990 # Dictionary is special-cased, but arrays and sequences shouldn't be |
988 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, | 991 'idl_type': idl_type.native_array_element_type, |
989 'index': index, | 992 'index': index, |
990 'is_array_or_sequence_type': not not idl_type.array_or_sequence_type, | 993 'is_array_or_sequence_type': not not idl_type.native_array_element_type, |
991 'is_optional': argument.is_optional, | 994 'is_optional': argument.is_optional, |
992 'is_strict_type_checking': False, # Required for overload resolution | 995 'is_strict_type_checking': False, # Required for overload resolution |
993 'name': argument.name, | 996 'name': argument.name, |
994 'dart_value_to_local_cpp_value': dart_methods.dart_value_to_local_cpp_va
lue(interface, argument, index), | 997 'dart_value_to_local_cpp_value': dart_methods.dart_value_to_local_cpp_va
lue(interface, argument, index), |
995 } | 998 } |
996 return argument_content | 999 return argument_content |
997 | 1000 |
998 | 1001 |
999 def generate_constructor_overloads(constructors): | 1002 def generate_constructor_overloads(constructors): |
1000 if len(constructors) <= 1: | 1003 if len(constructors) <= 1: |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 deleter = next( | 1229 deleter = next( |
1227 method | 1230 method |
1228 for method in interface.operations | 1231 for method in interface.operations |
1229 if ('deleter' in method.specials and | 1232 if ('deleter' in method.specials and |
1230 len(method.arguments) == 1 and | 1233 len(method.arguments) == 1 and |
1231 str(method.arguments[0].idl_type) == 'DOMString')) | 1234 str(method.arguments[0].idl_type) == 'DOMString')) |
1232 except StopIteration: | 1235 except StopIteration: |
1233 return None | 1236 return None |
1234 | 1237 |
1235 return property_deleter(deleter) | 1238 return property_deleter(deleter) |
OLD | NEW |