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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 for extended_attribute_name in extended_attributes: | 388 for extended_attribute_name in extended_attributes: |
389 ignore_extended_values = IGNORE_EXTENDED_ATTRIBUTES.get(extended_attribu
te_name) | 389 ignore_extended_values = IGNORE_EXTENDED_ATTRIBUTES.get(extended_attribu
te_name) |
390 if ignore_extended_values != None: | 390 if ignore_extended_values != None: |
391 extended_attribute_value = extended_attributes.get(extended_attribut
e_name) | 391 extended_attribute_value = extended_attributes.get(extended_attribut
e_name) |
392 if ((not ignore_extended_values and extended_attribute_value == None
) or | 392 if ((not ignore_extended_values and extended_attribute_value == None
) or |
393 extended_attribute_value in ignore_extended_values): | 393 extended_attribute_value in ignore_extended_values): |
394 return True | 394 return True |
395 return False | 395 return False |
396 | 396 |
397 | 397 |
| 398 def add_native_entries(interface, constructors, is_custom): |
| 399 for constructor in constructors: |
| 400 types = None |
| 401 if not is_custom: |
| 402 types = [arg['preprocessed_type'] |
| 403 for arg in constructor['arguments']] |
| 404 argument_names = [arg['name'] for arg in constructor['arguments']] |
| 405 native_entry = \ |
| 406 DartUtilities.generate_native_entry(interface.name, constructor, |
| 407 None, 'Constructor', None, |
| 408 argument_names, types) |
| 409 constructor.update({'native_entry': native_entry}) |
| 410 |
| 411 |
398 def generate_interface(interface): | 412 def generate_interface(interface): |
399 includes.clear() | 413 includes.clear() |
400 includes.update(INTERFACE_CPP_INCLUDES) | 414 includes.update(INTERFACE_CPP_INCLUDES) |
401 header_includes = set(INTERFACE_H_INCLUDES) | 415 header_includes = set(INTERFACE_H_INCLUDES) |
402 | 416 |
403 parent_interface = interface.parent | 417 parent_interface = interface.parent |
404 if parent_interface: | 418 if parent_interface: |
405 header_includes.update(dart_types.includes_for_interface(parent_interfac
e)) | 419 header_includes.update(dart_types.includes_for_interface(parent_interfac
e)) |
406 extended_attributes = interface.extended_attributes | 420 extended_attributes = interface.extended_attributes |
407 | 421 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 any_type_attributes = [attribute for attribute in interface.attributes | 547 any_type_attributes = [attribute for attribute in interface.attributes |
534 if attribute.idl_type.name == 'Any'] | 548 if attribute.idl_type.name == 'Any'] |
535 if has_event_constructor: | 549 if has_event_constructor: |
536 includes.add('bindings/common/Dictionary.h') | 550 includes.add('bindings/common/Dictionary.h') |
537 if any_type_attributes: | 551 if any_type_attributes: |
538 includes.add('bindings/v8/SerializedScriptValue.h') | 552 includes.add('bindings/v8/SerializedScriptValue.h') |
539 | 553 |
540 # [NamedConstructor] | 554 # [NamedConstructor] |
541 named_constructor = generate_named_constructor(interface) | 555 named_constructor = generate_named_constructor(interface) |
542 | 556 |
| 557 add_native_entries(interface, constructors, bool(custom_constructors)) |
| 558 add_native_entries(interface, custom_constructors, bool(custom_constructors)
) |
| 559 if named_constructor: |
| 560 add_native_entries(interface, [named_constructor], bool(custom_construct
ors)) |
| 561 |
543 if (constructors or custom_constructors or has_event_constructor or | 562 if (constructors or custom_constructors or has_event_constructor or |
544 named_constructor): | 563 named_constructor): |
545 includes.add('core/frame/LocalDOMWindow.h') | 564 includes.add('core/frame/LocalDOMWindow.h') |
546 | 565 |
547 template_contents.update({ | 566 template_contents.update({ |
548 'any_type_attributes': any_type_attributes, | 567 'any_type_attributes': any_type_attributes, |
549 'constructors': constructors, | 568 'constructors': constructors, |
550 'custom_constructors': custom_constructors, | 569 'custom_constructors': custom_constructors, |
551 'has_custom_constructor': bool(custom_constructors), | 570 'has_custom_constructor': bool(custom_constructors), |
552 'has_event_constructor': has_event_constructor, | 571 'has_event_constructor': has_event_constructor, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 not _suppress_extended_attributes(method.extended_attributes)
and | 621 not _suppress_extended_attributes(method.extended_attributes)
and |
603 not 'DartSuppress' in method.extended_attributes)] | 622 not 'DartSuppress' in method.extended_attributes)] |
604 generate_overloads(methods) | 623 generate_overloads(methods) |
605 for method in methods: | 624 for method in methods: |
606 method['do_generate_method_configuration'] = ( | 625 method['do_generate_method_configuration'] = ( |
607 method['do_not_check_signature'] and | 626 method['do_not_check_signature'] and |
608 not method['per_context_enabled_function'] and | 627 not method['per_context_enabled_function'] and |
609 # For overloaded methods, only generate one accessor | 628 # For overloaded methods, only generate one accessor |
610 ('overload_index' not in method or method['overload_index'] == 1)) | 629 ('overload_index' not in method or method['overload_index'] == 1)) |
611 | 630 |
| 631 generate_method_native_entries(interface, methods) |
| 632 |
612 template_contents.update({ | 633 template_contents.update({ |
613 'has_origin_safe_method_setter': any( | 634 'has_origin_safe_method_setter': any( |
614 method['is_check_security_for_frame'] and not method['is_read_only'] | 635 method['is_check_security_for_frame'] and not method['is_read_only'] |
615 for method in methods), | 636 for method in methods), |
616 'has_method_configuration': any(method['do_generate_method_configuration
'] for method in methods), | 637 'has_method_configuration': any(method['do_generate_method_configuration
'] for method in methods), |
617 'has_per_context_enabled_methods': any(method['per_context_enabled_funct
ion'] for method in methods), | 638 'has_per_context_enabled_methods': any(method['per_context_enabled_funct
ion'] for method in methods), |
618 'methods': methods, | 639 'methods': methods, |
619 }) | 640 }) |
620 | 641 |
| 642 native_entries = generate_native_entries(interface, constructors, |
| 643 custom_constructors, attributes, |
| 644 methods, named_constructor) |
| 645 |
621 template_contents.update({ | 646 template_contents.update({ |
622 'indexed_property_getter': indexed_property_getter(interface), | 647 'indexed_property_getter': indexed_property_getter(interface), |
623 'indexed_property_setter': indexed_property_setter(interface), | 648 'indexed_property_setter': indexed_property_setter(interface), |
624 'indexed_property_deleter': indexed_property_deleter(interface), | 649 'indexed_property_deleter': indexed_property_deleter(interface), |
625 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, | 650 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, |
626 'named_property_getter': named_property_getter(interface), | 651 'named_property_getter': named_property_getter(interface), |
627 'named_property_setter': named_property_setter(interface), | 652 'named_property_setter': named_property_setter(interface), |
628 'named_property_deleter': named_property_deleter(interface), | 653 'named_property_deleter': named_property_deleter(interface), |
| 654 'native_entries': native_entries, |
629 }) | 655 }) |
630 | 656 |
631 return template_contents | 657 return template_contents |
632 | 658 |
633 | 659 |
| 660 def generate_native_entries(interface, constructors, custom_constructors, |
| 661 attributes, methods, named_constructor): |
| 662 entries = [] |
| 663 for constructor in constructors: |
| 664 entries.append(constructor['native_entry']) |
| 665 for constructor in custom_constructors: |
| 666 entries.append(constructor['native_entry']) |
| 667 if named_constructor: |
| 668 entries.append(named_constructor['native_entry']) |
| 669 for method in methods: |
| 670 entries.extend(method['native_entries']) |
| 671 for attribute in attributes: |
| 672 entries.append(attribute['native_entry_getter']) |
| 673 entries.append(attribute['native_entry_setter']) |
| 674 return entries |
| 675 |
| 676 |
634 # [DeprecateAs], [Reflect], [RuntimeEnabled] | 677 # [DeprecateAs], [Reflect], [RuntimeEnabled] |
635 def generate_constant(constant): | 678 def generate_constant(constant): |
636 # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted | 679 # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted |
637 # in C++. | 680 # in C++. |
638 if constant.idl_type.name == 'String': | 681 if constant.idl_type.name == 'String': |
639 value = '"%s"' % constant.value | 682 value = '"%s"' % constant.value |
640 else: | 683 else: |
641 value = constant.value | 684 value = constant.value |
642 | 685 |
643 extended_attributes = constant.extended_attributes | 686 extended_attributes = constant.extended_attributes |
644 return { | 687 return { |
645 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), | 688 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), |
646 'name': constant.name, | 689 'name': constant.name, |
647 # FIXME: use 'reflected_name' as correct 'name' | 690 # FIXME: use 'reflected_name' as correct 'name' |
648 'reflected_name': extended_attributes.get('Reflect', constant.name), | 691 'reflected_name': extended_attributes.get('Reflect', constant.name), |
649 'runtime_enabled_function': DartUtilities.runtime_enabled_function_name(
constant), | 692 'runtime_enabled_function': DartUtilities.runtime_enabled_function_name(
constant), |
650 'value': value, | 693 'value': value, |
651 } | 694 } |
652 | 695 |
653 | 696 |
654 ################################################################################ | 697 ################################################################################ |
655 # Overloads | 698 # Overloads |
656 ################################################################################ | 699 ################################################################################ |
657 | 700 |
| 701 def generate_method_native_entry(interface, method, count, optional_index): |
| 702 types = None |
| 703 if not method['is_custom']: |
| 704 types = [arg['preprocessed_type'] for arg in method['arguments'][0:count
]] |
| 705 if method['is_call_with_script_arguments']: |
| 706 types.append("object") |
| 707 argument_names = [arg['name'] for arg in method['arguments'][0:count]] |
| 708 name = method['name'] |
| 709 native_entry = \ |
| 710 DartUtilities.generate_native_entry(interface.name, method, |
| 711 name, 'Method', |
| 712 optional_index, |
| 713 argument_names, types) |
| 714 return native_entry |
| 715 |
| 716 |
| 717 def generate_method_native_entries(interface, methods): |
| 718 for method in methods: |
| 719 native_entries = [] |
| 720 required_arg_count = method['number_of_required_arguments'] |
| 721 arg_count = method['number_of_arguments'] |
| 722 if required_arg_count != arg_count: |
| 723 for x in range(required_arg_count, arg_count + 1): |
| 724 # This is really silly, but is here for now just to match up |
| 725 # the existing name generation in the old dart:html scripts |
| 726 index = arg_count - x + 1 |
| 727 native_entry = \ |
| 728 generate_method_native_entry(interface, method, x, index) |
| 729 native_entries.append(native_entry) |
| 730 else: |
| 731 # Eventually, we should probably always generate an unindexed |
| 732 # native entry, to handle cases like |
| 733 # addEventListener in which we suppress the optionality, |
| 734 # and in general to make us more robust against optional changes |
| 735 native_entry = \ |
| 736 generate_method_native_entry(interface, method, arg_count, None) |
| 737 native_entries.append(native_entry) |
| 738 |
| 739 method.update({'native_entries': native_entries}) |
| 740 |
658 def generate_overloads(methods): | 741 def generate_overloads(methods): |
659 generate_overloads_by_type(methods, is_static=False) # Regular methods | 742 generate_overloads_by_type(methods, is_static=False) # Regular methods |
660 generate_overloads_by_type(methods, is_static=True) | 743 generate_overloads_by_type(methods, is_static=True) |
661 | 744 |
662 | 745 |
663 def generate_overloads_by_type(methods, is_static): | 746 def generate_overloads_by_type(methods, is_static): |
664 # Generates |overloads| template values and modifies |methods| in place; | 747 # Generates |overloads| template values and modifies |methods| in place; |
665 # |is_static| flag used (instead of partitioning list in 2) because need to | 748 # |is_static| flag used (instead of partitioning list in 2) because need to |
666 # iterate over original list of methods to modify in place | 749 # iterate over original list of methods to modify in place |
667 method_counts = defaultdict(lambda: 0) | 750 method_counts = defaultdict(lambda: 0) |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 'number_of_required_arguments': | 906 'number_of_required_arguments': |
824 number_of_required_arguments(constructor), | 907 number_of_required_arguments(constructor), |
825 } | 908 } |
826 | 909 |
827 | 910 |
828 # We don't need much from this - just the idl_type_objects and preproceed_type | 911 # We don't need much from this - just the idl_type_objects and preproceed_type |
829 # to use in generating the resolver strings. | 912 # to use in generating the resolver strings. |
830 def custom_constructor_argument(argument, index): | 913 def custom_constructor_argument(argument, index): |
831 return { | 914 return { |
832 'idl_type_object': argument.idl_type, | 915 'idl_type_object': argument.idl_type, |
833 'preprocessed_type': argument.idl_type.preprocessed_type, | 916 'name': argument.name, |
| 917 'preprocessed_type': str(argument.idl_type.preprocessed_type), |
834 } | 918 } |
835 | 919 |
836 | 920 |
837 # [Constructor] | 921 # [Constructor] |
838 def generate_constructor(interface, constructor): | 922 def generate_constructor(interface, constructor): |
839 return { | 923 return { |
840 'argument_list': constructor_argument_list(interface, constructor), | 924 'argument_list': constructor_argument_list(interface, constructor), |
841 # TODO(terry): Use dart_methods.generate_argument instead constructor_ar
gument. | 925 # TODO(terry): Use dart_methods.generate_argument instead constructor_ar
gument. |
842 'arguments': [constructor_argument(interface, argument, index) | 926 'arguments': [constructor_argument(interface, argument, index) |
843 for index, argument in enumerate(constructor.arguments)], | 927 for index, argument in enumerate(constructor.arguments)], |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 default_value = str(argument.default_value) if argument.default_value else N
one | 976 default_value = str(argument.default_value) if argument.default_value else N
one |
893 | 977 |
894 argument_content = { | 978 argument_content = { |
895 'cpp_type': idl_type.cpp_type_args(), | 979 'cpp_type': idl_type.cpp_type_args(), |
896 'local_cpp_type': idl_type.cpp_type_args(argument.extended_attributes, u
sed_as_argument=True), | 980 'local_cpp_type': idl_type.cpp_type_args(argument.extended_attributes, u
sed_as_argument=True), |
897 # FIXME: check that the default value's type is compatible with the argu
ment's | 981 # FIXME: check that the default value's type is compatible with the argu
ment's |
898 'default_value': default_value, | 982 'default_value': default_value, |
899 # FIXME: remove once [Default] removed and just use argument.default_val
ue | 983 # FIXME: remove once [Default] removed and just use argument.default_val
ue |
900 'has_default': 'Default' in argument.extended_attributes or default_valu
e, | 984 'has_default': 'Default' in argument.extended_attributes or default_valu
e, |
901 'idl_type_object': idl_type, | 985 'idl_type_object': idl_type, |
902 'preprocessed_type': idl_type.preprocessed_type, | 986 'preprocessed_type': str(idl_type.preprocessed_type), |
903 # Dictionary is special-cased, but arrays and sequences shouldn't be | 987 # Dictionary is special-cased, but arrays and sequences shouldn't be |
904 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, | 988 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, |
905 'index': index, | 989 'index': index, |
906 'is_array_or_sequence_type': not not idl_type.array_or_sequence_type, | 990 'is_array_or_sequence_type': not not idl_type.array_or_sequence_type, |
907 'is_optional': argument.is_optional, | 991 'is_optional': argument.is_optional, |
908 'is_strict_type_checking': False, # Required for overload resolution | 992 'is_strict_type_checking': False, # Required for overload resolution |
909 'name': argument.name, | 993 'name': argument.name, |
910 'dart_value_to_local_cpp_value': dart_methods.dart_value_to_local_cpp_va
lue(interface, argument, index), | 994 'dart_value_to_local_cpp_value': dart_methods.dart_value_to_local_cpp_va
lue(interface, argument, index), |
911 } | 995 } |
912 return argument_content | 996 return argument_content |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 deleter = next( | 1226 deleter = next( |
1143 method | 1227 method |
1144 for method in interface.operations | 1228 for method in interface.operations |
1145 if ('deleter' in method.specials and | 1229 if ('deleter' in method.specials and |
1146 len(method.arguments) == 1 and | 1230 len(method.arguments) == 1 and |
1147 str(method.arguments[0].idl_type) == 'DOMString')) | 1231 str(method.arguments[0].idl_type) == 'DOMString')) |
1148 except StopIteration: | 1232 except StopIteration: |
1149 return None | 1233 return None |
1150 | 1234 |
1151 return property_deleter(deleter) | 1235 return property_deleter(deleter) |
OLD | NEW |