OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 """This module provides shared functionality for the system to generate | 6 """This module provides shared functionality for the system to generate |
7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
8 | 8 |
9 import emitter | 9 import emitter |
10 | 10 |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 return _html_event_names[event_name] | 611 return _html_event_names[event_name] |
612 | 612 |
613 # ------------------------------------------------------------------------------ | 613 # ------------------------------------------------------------------------------ |
614 class HtmlSystemShared(object): | 614 class HtmlSystemShared(object): |
615 | 615 |
616 def __init__(self, database): | 616 def __init__(self, database): |
617 self._event_classes = set() | 617 self._event_classes = set() |
618 self._seen_event_names = {} | 618 self._seen_event_names = {} |
619 self._database = database | 619 self._database = database |
620 self._inheritance_closure = _ComputeInheritanceClosure(database) | 620 self._inheritance_closure = _ComputeInheritanceClosure(database) |
621 self._html_renames = self._MakeHtmlRenames() | |
622 | 621 |
623 def _HasAncestor(self, interface, names_to_match): | 622 def _HasAncestor(self, interface, names_to_match): |
624 for parent in interface.parents: | 623 for parent in interface.parents: |
625 if parent.type.id in names_to_match: | 624 if parent.type.id in names_to_match: |
626 return True | 625 return True |
627 if not self._database.HasInterface(parent.type.id): | 626 if not self._database.HasInterface(parent.type.id): |
628 continue | 627 continue |
629 parent_interface = self._database.GetInterface(parent.type.id) | 628 parent_interface = self._database.GetInterface(parent.type.id) |
630 if self._HasAncestor(parent_interface, names_to_match): | 629 if self._HasAncestor(parent_interface, names_to_match): |
631 return True | 630 return True |
632 return False | 631 return False |
633 | 632 |
634 def _MakeHtmlRenames(self): | 633 def MakeHtmlRenames(self): |
635 html_renames = {} | 634 html_renames = {} |
636 | 635 |
637 for interface in self._database.GetInterfaces(): | 636 for interface in self._database.GetInterfaces(): |
638 if (interface.id.startswith('HTML') and | 637 if (interface.id.startswith('HTML') and |
639 self._HasAncestor(interface, ['Element', 'Document'])): | 638 self._HasAncestor(interface, ['Element', 'Document'])): |
640 html_renames[interface.id] = interface.id[4:] | 639 html_renames[interface.id] = interface.id[4:] |
641 | 640 |
642 for subclass in _html_strip_webkit_prefix_classes: | 641 for subclass in _html_strip_webkit_prefix_classes: |
643 html_renames['WebKit' + subclass] = subclass | 642 html_renames['WebKit' + subclass] = subclass |
644 | 643 |
645 # TODO(jacobr): we almost want to add this commented out line back. | 644 # TODO(jacobr): we almost want to add this commented out line back. |
646 # html_renames['HTMLCollection'] = 'ElementList' | 645 # html_renames['HTMLCollection'] = 'ElementList' |
647 # html_renames['NodeList'] = 'ElementList' | 646 # html_renames['NodeList'] = 'ElementList' |
648 # html_renames['HTMLOptionsCollection'] = 'ElementList' | 647 # html_renames['HTMLOptionsCollection'] = 'ElementList' |
649 html_renames['DOMWindow'] = 'Window' | 648 html_renames['DOMWindow'] = 'Window' |
650 | 649 |
651 return html_renames | 650 return html_renames |
652 | 651 |
653 def _HTMLInterfaceName(self, interface_name): | |
654 return self._html_renames.get(interface_name, interface_name) | |
655 | |
656 def _FindMatch(self, interface_name, member, member_prefix, candidates): | 652 def _FindMatch(self, interface_name, member, member_prefix, candidates): |
657 for ancestor_name in self._AllAncestorInterfaces(interface_name): | 653 for ancestor_name in self._AllAncestorInterfaces(interface_name): |
658 name = self._HTMLInterfaceName(ancestor_name) + '.' + member | 654 name = DartType(ancestor_name) + '.' + member |
659 if name in candidates: | 655 if name in candidates: |
660 return name | 656 return name |
661 name = (self._HTMLInterfaceName(interface_name) + '.' + member_prefix + | 657 name = (DartType(interface_name) + '.' + member_prefix + |
662 member) | 658 member) |
663 if name in candidates: | 659 if name in candidates: |
664 return name | 660 return name |
665 return None | 661 return None |
666 | 662 |
667 def _AllAncestorInterfaces(self, interface_name): | 663 def _AllAncestorInterfaces(self, interface_name): |
668 return [interface_name] + self._inheritance_closure[interface_name] | 664 return [interface_name] + self._inheritance_closure[interface_name] |
669 | 665 |
670 def RenameInHtmlLibrary(self, interface_name, member, member_prefix='', | 666 def RenameInHtmlLibrary(self, interface_name, member, member_prefix='', |
671 implementation_class=False): | 667 implementation_class=False): |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 for interface in interfaces_with_events: | 718 for interface in interfaces_with_events: |
723 names.append(interface.id + 'Events') | 719 names.append(interface.id + 'Events') |
724 return names | 720 return names |
725 | 721 |
726 def GetParentEventsClass(self, interface): | 722 def GetParentEventsClass(self, interface): |
727 parent_event_classes = self.GetParentsEventsClasses(interface) | 723 parent_event_classes = self.GetParentsEventsClasses(interface) |
728 if len(parent_event_classes) != 1: | 724 if len(parent_event_classes) != 1: |
729 raise Exception('Only one parent event class allowed ' + interface.id) | 725 raise Exception('Only one parent event class allowed ' + interface.id) |
730 return parent_event_classes[0] | 726 return parent_event_classes[0] |
731 | 727 |
732 def _ImplClassName(self, type_name): | |
733 return '_' + type_name + 'Impl' | |
734 | |
735 # This returns two values: the first is whether or not an "on" property should | 728 # This returns two values: the first is whether or not an "on" property should |
736 # be generated for the interface, and the second is the event attributes to | 729 # be generated for the interface, and the second is the event attributes to |
737 # generate if it should. | 730 # generate if it should. |
738 def GetEventAttributes(self, interface): | 731 def GetEventAttributes(self, interface): |
739 events = set([attr for attr in interface.attributes | 732 events = set([attr for attr in interface.attributes |
740 if attr.type.id == 'EventListener']) | 733 if attr.type.id == 'EventListener']) |
741 | 734 |
742 if events or interface.id in _html_explicit_event_classes: | 735 if events or interface.id in _html_explicit_event_classes: |
743 return True, events | 736 return True, events |
744 else: | 737 else: |
745 return False, None | 738 return False, None |
746 | 739 |
747 def IsPrivate(self, name): | 740 def IsPrivate(self, name): |
748 return name.startswith('_') | 741 return name.startswith('_') |
749 | 742 |
750 def DartType(self, idl_type): | |
751 type_info = GetIDLTypeInfo(idl_type) | |
752 return self._HTMLInterfaceName(type_info.dart_type()) | |
753 | 743 |
754 class HtmlSystem(System): | 744 class HtmlInterfacesSystem(System): |
755 | |
756 def __init__(self, templates, database, emitters, output_dir): | |
757 super(HtmlSystem, self).__init__( | |
758 templates, database, emitters, output_dir) | |
759 self._shared = HtmlSystemShared(database) | |
760 | |
761 class HtmlInterfacesSystem(HtmlSystem): | |
762 | 745 |
763 def __init__(self, templates, database, emitters, output_dir, backend): | 746 def __init__(self, templates, database, emitters, output_dir, backend): |
764 super(HtmlInterfacesSystem, self).__init__( | 747 super(HtmlInterfacesSystem, self).__init__( |
765 templates, database, emitters, output_dir) | 748 templates, database, emitters, output_dir) |
| 749 self._shared = HtmlSystemShared(database) |
766 self._backend = backend | 750 self._backend = backend |
767 self._dart_interface_file_paths = [] | 751 self._dart_interface_file_paths = [] |
768 self._elements_factory_emitter = None | 752 self._elements_factory_emitter = None |
769 | 753 |
770 def ProcessInterface(self, interface): | 754 def ProcessInterface(self, interface): |
771 HtmlDartInterfaceGenerator(self, interface).Generate() | 755 HtmlDartInterfaceGenerator(self, interface).Generate() |
772 | 756 |
773 def ProcessCallback(self, interface, info): | 757 def ProcessCallback(self, interface, info): |
774 """Generates a typedef for the callback interface.""" | 758 """Generates a typedef for the callback interface.""" |
775 interface_name = interface.id | 759 interface_name = interface.id |
(...skipping 13 matching lines...) Expand all Loading... |
789 # ------------------------------------------------------------------------------ | 773 # ------------------------------------------------------------------------------ |
790 | 774 |
791 class HtmlDartInterfaceGenerator(BaseGenerator): | 775 class HtmlDartInterfaceGenerator(BaseGenerator): |
792 """Generates dart interface and implementation for the DOM IDL interface.""" | 776 """Generates dart interface and implementation for the DOM IDL interface.""" |
793 | 777 |
794 def __init__(self, system, interface): | 778 def __init__(self, system, interface): |
795 super(HtmlDartInterfaceGenerator, self).__init__( | 779 super(HtmlDartInterfaceGenerator, self).__init__( |
796 system._database, interface) | 780 system._database, interface) |
797 self._system = system | 781 self._system = system |
798 self._shared = system._shared | 782 self._shared = system._shared |
799 self._html_interface_name = self._shared._HTMLInterfaceName( | 783 self._html_interface_name = DartInterfaceName(self._interface) |
800 self._interface.id) | |
801 self._backend = system._backend.ImplementationGenerator(self._interface) | 784 self._backend = system._backend.ImplementationGenerator(self._interface) |
802 | 785 |
803 def StartInterface(self): | 786 def StartInterface(self): |
804 if not self._interface.id in _merged_html_interfaces: | 787 if not self._interface.id in _merged_html_interfaces: |
805 path = self._system._FilePathForDartInterface(self._html_interface_name) | 788 path = self._system._FilePathForDartInterface(self._html_interface_name) |
806 self._system._dart_interface_file_paths.append(path) | 789 self._system._dart_interface_file_paths.append(path) |
807 self._interface_emitter = self._system._emitters.FileEmitter(path) | 790 self._interface_emitter = self._system._emitters.FileEmitter(path) |
808 else: | 791 else: |
809 self._interface_emitter = emitter.Emitter() | 792 self._interface_emitter = emitter.Emitter() |
810 | 793 |
811 template_file = 'interface_%s.darttemplate' % self._html_interface_name | 794 template_file = 'interface_%s.darttemplate' % self._html_interface_name |
812 interface_template = (self._system._templates.TryLoad(template_file) or | 795 interface_template = (self._system._templates.TryLoad(template_file) or |
813 self._system._templates.Load('interface.darttemplate')
) | 796 self._system._templates.Load('interface.darttemplate')
) |
814 | 797 |
815 typename = self._html_interface_name | 798 typename = self._html_interface_name |
816 | 799 |
817 extends = [] | 800 extends = [] |
818 suppressed_extends = [] | 801 suppressed_extends = [] |
819 | 802 |
820 for parent in self._interface.parents: | 803 for parent in self._interface.parents: |
821 # TODO(vsm): Remove source_filter. | 804 # TODO(vsm): Remove source_filter. |
822 if MatchSourceFilter(parent): | 805 if MatchSourceFilter(parent): |
823 # Parent is a DOM type. | 806 # Parent is a DOM type. |
824 extends.append(self._shared.DartType(parent.type.id)) | 807 extends.append(DartType(parent.type.id)) |
825 elif '<' in parent.type.id: | 808 elif '<' in parent.type.id: |
826 # Parent is a Dart collection type. | 809 # Parent is a Dart collection type. |
827 # TODO(vsm): Make this check more robust. | 810 # TODO(vsm): Make this check more robust. |
828 extends.append(self._shared.DartType(parent.type.id)) | 811 extends.append(DartType(parent.type.id)) |
829 else: | 812 else: |
830 suppressed_extends.append('%s.%s' % | 813 suppressed_extends.append('%s.%s' % |
831 (self._common_prefix, self._shared.DartType(parent.type.id))) | 814 (self._common_prefix, DartType(parent.type.id))) |
832 | 815 |
833 comment = ' extends' | 816 comment = ' extends' |
834 extends_str = '' | 817 extends_str = '' |
835 if extends: | 818 if extends: |
836 extends_str += ' extends ' + ', '.join(extends) | 819 extends_str += ' extends ' + ', '.join(extends) |
837 comment = ',' | 820 comment = ',' |
838 if suppressed_extends: | 821 if suppressed_extends: |
839 extends_str += ' /*%s %s */' % (comment, ', '.join(suppressed_extends)) | 822 extends_str += ' /*%s %s */' % (comment, ', '.join(suppressed_extends)) |
840 | 823 |
841 factory_provider = None | 824 factory_provider = None |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 self._implementation_emitter = self._system._emitters.FileEmitter(path) | 878 self._implementation_emitter = self._system._emitters.FileEmitter(path) |
896 else: | 879 else: |
897 self._implementation_emitter = emitter.Emitter() | 880 self._implementation_emitter = emitter.Emitter() |
898 self._backend.SetImplementationEmitter(self._implementation_emitter) | 881 self._backend.SetImplementationEmitter(self._implementation_emitter) |
899 self._implementation_members_emitter = self._backend.StartInterface() | 882 self._implementation_members_emitter = self._backend.StartInterface() |
900 | 883 |
901 for constructor_info in constructors: | 884 for constructor_info in constructors: |
902 self._members_emitter.Emit( | 885 self._members_emitter.Emit( |
903 '\n' | 886 '\n' |
904 ' $CTOR($PARAMS);\n', | 887 ' $CTOR($PARAMS);\n', |
905 CTOR=self._shared.DartType(constructor_info.ConstructorFullName()), | 888 CTOR=DartType(constructor_info.ConstructorFullName()), |
906 PARAMS=constructor_info.ParametersInterfaceDeclaration( | 889 PARAMS=constructor_info.ParametersInterfaceDeclaration()) |
907 self._shared.DartType)) | |
908 | 890 |
909 element_type = MaybeTypedArrayElementTypeInHierarchy( | 891 element_type = MaybeTypedArrayElementTypeInHierarchy( |
910 self._interface, self._system._database) | 892 self._interface, self._system._database) |
911 if element_type: | 893 if element_type: |
912 self._members_emitter.Emit( | 894 self._members_emitter.Emit( |
913 '\n' | 895 '\n' |
914 ' $CTOR(int length);\n' | 896 ' $CTOR(int length);\n' |
915 '\n' | 897 '\n' |
916 ' $CTOR.fromList(List<$TYPE> list);\n' | 898 ' $CTOR.fromList(List<$TYPE> list);\n' |
917 '\n' | 899 '\n' |
918 ' $CTOR.fromBuffer(ArrayBuffer buffer,' | 900 ' $CTOR.fromBuffer(ArrayBuffer buffer,' |
919 ' [int byteOffset, int length]);\n', | 901 ' [int byteOffset, int length]);\n', |
920 CTOR=self._interface.id, | 902 CTOR=self._interface.id, |
921 TYPE=self._shared.DartType(element_type)) | 903 TYPE=DartType(element_type)) |
922 | 904 |
923 self._GenerateEvents() | 905 self._GenerateEvents() |
924 | 906 |
925 old_backend = self._backend | 907 old_backend = self._backend |
926 if not self._backend.ImplementsMergedMembers(): | 908 if not self._backend.ImplementsMergedMembers(): |
927 self._backend = HtmlGeneratorDummyBackend() | 909 self._backend = HtmlGeneratorDummyBackend() |
928 for merged_interface in _merged_html_interfaces: | 910 for merged_interface in _merged_html_interfaces: |
929 if _merged_html_interfaces[merged_interface] == self._interface.id: | 911 if _merged_html_interfaces[merged_interface] == self._interface.id: |
930 merged_interface = self._database.GetInterface(merged_interface) | 912 merged_interface = self._database.GetInterface(merged_interface) |
931 self.AddMembers(merged_interface) | 913 self.AddMembers(merged_interface) |
(...skipping 21 matching lines...) Expand all Loading... |
953 assert(not html_setter_name or html_name == html_setter_name) | 935 assert(not html_setter_name or html_name == html_setter_name) |
954 | 936 |
955 if not is_secondary: | 937 if not is_secondary: |
956 self._members_emitter.Emit('\n /** @domName $DOMINTERFACE.$DOMNAME */', | 938 self._members_emitter.Emit('\n /** @domName $DOMINTERFACE.$DOMNAME */', |
957 DOMINTERFACE=attribute.doc_js_interface_name, | 939 DOMINTERFACE=attribute.doc_js_interface_name, |
958 DOMNAME=dom_name) | 940 DOMNAME=dom_name) |
959 modifier = 'final ' if read_only else '' | 941 modifier = 'final ' if read_only else '' |
960 self._members_emitter.Emit('\n $MODIFIER$TYPE $NAME;\n', | 942 self._members_emitter.Emit('\n $MODIFIER$TYPE $NAME;\n', |
961 MODIFIER=modifier, | 943 MODIFIER=modifier, |
962 NAME=html_name, | 944 NAME=html_name, |
963 TYPE=self._shared.DartType(attribute.type.id)) | 945 TYPE=DartType(attribute.type.id)) |
964 self._backend.AddAttribute(attribute, html_name, read_only) | 946 self._backend.AddAttribute(attribute, html_name, read_only) |
965 | 947 |
966 def AddSecondaryAttribute(self, interface, attribute): | 948 def AddSecondaryAttribute(self, interface, attribute): |
967 self._backend.SecondaryContext(interface) | 949 self._backend.SecondaryContext(interface) |
968 self.AddAttribute(attribute, True) | 950 self.AddAttribute(attribute, True) |
969 | 951 |
970 def AddOperation(self, info, is_secondary=False): | 952 def AddOperation(self, info, skip_declaration=False): |
971 """ | 953 """ |
972 Arguments: | 954 Arguments: |
973 operations - contains the overloads, one or more operations with the same | 955 operations - contains the overloads, one or more operations with the same |
974 name. | 956 name. |
975 """ | 957 """ |
976 html_name = self._shared.RenameInHtmlLibrary( | 958 html_name = self._shared.RenameInHtmlLibrary(self._interface.id, info.name) |
977 self._interface.id, info.name) | 959 if not html_name: |
978 if html_name and not self._shared.IsPrivate(html_name) and not is_secondary: | 960 if info.name == 'item': |
| 961 # FIXME: item should be renamed to operator[], not removed. |
| 962 self._backend.AddOperation(info, '_item') |
| 963 return |
| 964 |
| 965 if not self._shared.IsPrivate(html_name) and not skip_declaration: |
979 self._members_emitter.Emit('\n /** @domName $DOMINTERFACE.$DOMNAME */', | 966 self._members_emitter.Emit('\n /** @domName $DOMINTERFACE.$DOMNAME */', |
980 DOMINTERFACE=info.overloads[0].doc_js_interface_name, | 967 DOMINTERFACE=info.overloads[0].doc_js_interface_name, |
981 DOMNAME=info.name) | 968 DOMNAME=info.name) |
982 | 969 |
983 self._members_emitter.Emit('\n' | 970 self._members_emitter.Emit('\n' |
984 ' $TYPE $NAME($PARAMS);\n', | 971 ' $TYPE $NAME($PARAMS);\n', |
985 TYPE=self._shared.DartType(info.type_name), | 972 TYPE=DartType(info.type_name), |
986 NAME=html_name, | 973 NAME=html_name, |
987 PARAMS=info.ParametersInterfaceDeclaration( | 974 PARAMS=info.ParametersInterfaceDeclaration()) |
988 self._shared.DartType)) | 975 self._backend.AddOperation(info, html_name) |
989 self._backend.AddOperation(info) | |
990 | 976 |
991 def AddStaticOperation(self, info): | 977 def AddStaticOperation(self, info): |
992 self._backend.AddStaticOperation(info) | 978 self.AddOperation(info, True) |
993 | 979 |
994 def AddSecondaryOperation(self, interface, info): | 980 def AddSecondaryOperation(self, interface, info): |
995 self._backend.SecondaryContext(interface) | 981 self._backend.SecondaryContext(interface) |
996 self.AddOperation(info, True) | 982 self.AddOperation(info, True) |
997 | 983 |
998 def FinishInterface(self): | 984 def FinishInterface(self): |
999 self._backend.FinishInterface() | 985 self._backend.FinishInterface() |
1000 | 986 |
1001 def AddConstant(self, constant): | 987 def AddConstant(self, constant): |
1002 type = TypeOrNothing(DartType(constant.type.id), constant.type.id) | 988 type = TypeOrNothing(DartType(constant.type.id), constant.type.id) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 | 1049 |
1064 self._implementation_members_emitter.Emit( | 1050 self._implementation_members_emitter.Emit( |
1065 '\n $TYPE get on() =>\n new $TYPE(this);\n', | 1051 '\n $TYPE get on() =>\n new $TYPE(this);\n', |
1066 TYPE=events_class) | 1052 TYPE=events_class) |
1067 | 1053 |
1068 | 1054 |
1069 class HtmlGeneratorDummyBackend(object): | 1055 class HtmlGeneratorDummyBackend(object): |
1070 def AddAttribute(self, attribute, html_name, read_only): | 1056 def AddAttribute(self, attribute, html_name, read_only): |
1071 pass | 1057 pass |
1072 | 1058 |
1073 def AddOperation(self, info): | 1059 def AddOperation(self, info, html_name): |
1074 pass | 1060 pass |
1075 | 1061 |
1076 | 1062 |
1077 # ------------------------------------------------------------------------------ | 1063 # ------------------------------------------------------------------------------ |
1078 | 1064 |
1079 # TODO(jmesserly): inheritance is probably not the right way to factor this long | 1065 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
1080 # term, but it makes merging better for now. | 1066 # term, but it makes merging better for now. |
1081 class HtmlFrogClassGenerator(FrogInterfaceGenerator): | 1067 class HtmlFrogClassGenerator(FrogInterfaceGenerator): |
1082 """Generates a Frog class for the dart:html library from a DOM IDL | 1068 """Generates a Frog class for the dart:html library from a DOM IDL |
1083 interface. | 1069 interface. |
1084 """ | 1070 """ |
1085 | 1071 |
1086 def __init__(self, system, interface): | 1072 def __init__(self, system, interface): |
1087 super(HtmlFrogClassGenerator, self).__init__( | 1073 super(HtmlFrogClassGenerator, self).__init__( |
1088 system, interface, None, None) | 1074 system, interface, None, None) |
1089 self._shared = self._system._shared | 1075 self._html_interface_name = DartInterfaceName(self._interface) |
1090 self._html_interface_name = self._shared._HTMLInterfaceName( | |
1091 self._interface.id) | |
1092 | 1076 |
1093 def HasImplementation(self): | 1077 def HasImplementation(self): |
1094 return not (IsPureInterface(self._interface.id) or | 1078 return not (IsPureInterface(self._interface.id) or |
1095 self._interface.id in _merged_html_interfaces) | 1079 self._interface.id in _merged_html_interfaces) |
1096 | 1080 |
1097 def ImplementationClassName(self): | 1081 def ImplementationClassName(self): |
1098 return self._ImplClassName(self._html_interface_name) | 1082 return self._ImplClassName(self._html_interface_name) |
1099 | 1083 |
1100 def FilePathForDartImplementation(self): | 1084 def FilePathForDartImplementation(self): |
1101 return os.path.join(self._system._output_dir, 'html', 'frog', | 1085 return os.path.join(self._system._output_dir, 'html', 'frog', |
1102 '%s.dart' % self._html_interface_name) | 1086 '%s.dart' % self._html_interface_name) |
1103 | 1087 |
1104 def FilePathForDartFactoryProviderImplementation(self): | 1088 def FilePathForDartFactoryProviderImplementation(self): |
1105 return os.path.join(self._system._output_dir, 'html', 'frog', | 1089 return os.path.join(self._system._output_dir, 'html', 'frog', |
1106 '_%sFactoryProvider.dart' % self._html_interface_name) | 1090 '_%sFactoryProvider.dart' % self._html_interface_name) |
1107 | 1091 |
1108 def FilePathForDartElementsFactoryProviderImplementation(self): | 1092 def FilePathForDartElementsFactoryProviderImplementation(self): |
1109 return os.path.join(self._system._output_dir, 'html', 'frog', | 1093 return os.path.join(self._system._output_dir, 'html', 'frog', |
1110 '_Elements.dart') | 1094 '_Elements.dart') |
1111 | 1095 |
1112 def SetImplementationEmitter(self, implementation_emitter): | 1096 def SetImplementationEmitter(self, implementation_emitter): |
1113 self._dart_code = implementation_emitter | 1097 self._dart_code = implementation_emitter |
1114 | 1098 |
1115 def ImplementsMergedMembers(self): | 1099 def ImplementsMergedMembers(self): |
1116 return True | 1100 return True |
1117 | 1101 |
1118 def _ImplClassName(self, type_name): | 1102 def _ImplClassName(self, type_name): |
1119 return self._shared._ImplClassName(type_name) | 1103 return '_%sImpl' % type_name |
1120 | |
1121 def _NarrowToImplementationType(self, type_name): | |
1122 if self._ShouldNarrowToImplementationType(type_name): | |
1123 return self._ImplClassName(self._shared.DartType(type_name)) | |
1124 return self._shared.DartType(type_name) | |
1125 | 1104 |
1126 def StartInterface(self): | 1105 def StartInterface(self): |
1127 interface = self._interface | 1106 interface = self._interface |
1128 interface_name = interface.id | 1107 interface_name = interface.id |
1129 | 1108 |
1130 self._class_name = self._ImplClassName(self._html_interface_name) | 1109 self._class_name = self._ImplClassName(self._html_interface_name) |
1131 | 1110 |
1132 base = None | 1111 base = None |
1133 if interface.parents: | 1112 if interface.parents: |
1134 supertype = interface.parents[0].type.id | 1113 supertype = interface.parents[0].type.id |
1135 if IsDartCollectionType(supertype): | 1114 if IsDartCollectionType(supertype): |
1136 # List methods are injected in AddIndexer. | 1115 # List methods are injected in AddIndexer. |
1137 pass | 1116 pass |
1138 elif IsPureInterface(supertype): | 1117 elif IsPureInterface(supertype): |
1139 pass | 1118 pass |
1140 else: | 1119 else: |
1141 base = self._ImplClassName(self._shared._HTMLInterfaceName(supertype)) | 1120 base = self._ImplClassName(DartType(supertype)) |
1142 | 1121 |
1143 native_spec = MakeNativeSpec(interface.javascript_binding_name) | 1122 native_spec = MakeNativeSpec(interface.javascript_binding_name) |
1144 | 1123 |
1145 extends = ' extends ' + base if base else '' | 1124 extends = ' extends ' + base if base else '' |
1146 | 1125 |
1147 # TODO: Include all implemented interfaces, including other Lists. | 1126 # TODO: Include all implemented interfaces, including other Lists. |
1148 implements = [self._html_interface_name] | 1127 implements = [self._html_interface_name] |
1149 element_type = MaybeTypedArrayElementType(self._interface) | 1128 element_type = MaybeTypedArrayElementType(self._interface) |
1150 if element_type: | 1129 if element_type: |
1151 implements.append('List<%s>' % self._shared.DartType(element_type)) | 1130 implements.append('List<%s>' % DartType(element_type)) |
1152 implements.append('JavaScriptIndexingBehavior') | 1131 implements.append('JavaScriptIndexingBehavior') |
1153 | 1132 |
1154 template_file = 'impl_%s.darttemplate' % self._html_interface_name | 1133 template_file = 'impl_%s.darttemplate' % self._html_interface_name |
1155 template = (self._system._templates.TryLoad(template_file) or | 1134 template = (self._system._templates.TryLoad(template_file) or |
1156 self._system._templates.Load('frog_impl.darttemplate')) | 1135 self._system._templates.Load('frog_impl.darttemplate')) |
1157 self._members_emitter = self._dart_code.Emit( | 1136 self._members_emitter = self._dart_code.Emit( |
1158 template, | 1137 template, |
1159 #class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 1138 #class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
1160 #$!MEMBERS | 1139 #$!MEMBERS |
1161 #} | 1140 #} |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 ' void operator[]=(int index, $TYPE value) {\n' | 1202 ' void operator[]=(int index, $TYPE value) {\n' |
1224 ' throw new UnsupportedOperationException("Cannot assign element
of immutable List.");\n' | 1203 ' throw new UnsupportedOperationException("Cannot assign element
of immutable List.");\n' |
1225 ' }\n', | 1204 ' }\n', |
1226 TYPE=self._NarrowInputType(element_type)) | 1205 TYPE=self._NarrowInputType(element_type)) |
1227 | 1206 |
1228 # TODO(sra): Use separate mixins for mutable implementations of List<T>. | 1207 # TODO(sra): Use separate mixins for mutable implementations of List<T>. |
1229 # TODO(sra): Use separate mixins for typed array implementations of List<T>. | 1208 # TODO(sra): Use separate mixins for typed array implementations of List<T>. |
1230 if self._interface.id != 'NodeList': | 1209 if self._interface.id != 'NodeList': |
1231 template_file = 'immutable_list_mixin.darttemplate' | 1210 template_file = 'immutable_list_mixin.darttemplate' |
1232 template = self._system._templates.Load(template_file) | 1211 template = self._system._templates.Load(template_file) |
1233 self._members_emitter.Emit(template, E=self._shared.DartType(element_type)
) | 1212 self._members_emitter.Emit(template, E=DartType(element_type)) |
1234 | 1213 |
1235 def AddAttribute(self, attribute, html_name, read_only): | 1214 def AddAttribute(self, attribute, html_name, read_only): |
1236 if self._HasCustomImplementation(attribute.id): | 1215 if self._HasCustomImplementation(attribute.id): |
1237 return | 1216 return |
1238 | 1217 |
1239 if attribute.id != html_name: | 1218 if attribute.id != html_name: |
1240 self._AddRenamingGetter(attribute, html_name) | 1219 self._AddRenamingGetter(attribute, html_name) |
1241 if not read_only: | 1220 if not read_only: |
1242 self._AddRenamingSetter(attribute, html_name) | 1221 self._AddRenamingSetter(attribute, html_name) |
1243 return | 1222 return |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 TYPE=return_type) | 1275 TYPE=return_type) |
1297 | 1276 |
1298 def _AddRenamingSetter(self, attr, html_name): | 1277 def _AddRenamingSetter(self, attr, html_name): |
1299 self._members_emitter.Emit( | 1278 self._members_emitter.Emit( |
1300 '\n void set $HTML_NAME($TYPE value)' | 1279 '\n void set $HTML_NAME($TYPE value)' |
1301 ' native "this.$NAME = value;";\n', | 1280 ' native "this.$NAME = value;";\n', |
1302 HTML_NAME=html_name, | 1281 HTML_NAME=html_name, |
1303 NAME=attr.id, | 1282 NAME=attr.id, |
1304 TYPE=self._NarrowInputType(attr.type.id)) | 1283 TYPE=self._NarrowInputType(attr.type.id)) |
1305 | 1284 |
1306 def AddOperation(self, info): | 1285 def AddOperation(self, info, html_name): |
1307 """ | 1286 """ |
1308 Arguments: | 1287 Arguments: |
1309 info: An OperationInfo object. | 1288 info: An OperationInfo object. |
1310 """ | 1289 """ |
1311 if self._HasCustomImplementation(info.name): | 1290 if self._HasCustomImplementation(info.name): |
1312 return | 1291 return |
1313 | 1292 |
1314 html_name = self._shared.RenameInHtmlLibrary( | 1293 # FIXME: support static operations. |
1315 self._interface.id, info.name, implementation_class=True) | 1294 if info.IsStatic(): |
1316 if not html_name: | |
1317 return | 1295 return |
1318 | 1296 |
1319 # Do we need a native body? | 1297 # Do we need a native body? |
1320 if html_name != info.declared_name: | 1298 if html_name != info.declared_name: |
1321 return_type = self._NarrowOutputType(info.type_name) | 1299 return_type = self._NarrowOutputType(info.type_name) |
1322 | 1300 |
1323 operation_emitter = self._members_emitter.Emit('$!SCOPE', | 1301 operation_emitter = self._members_emitter.Emit('$!SCOPE', |
1324 TYPE=return_type, | 1302 TYPE=return_type, |
1325 HTML_NAME=html_name, | 1303 HTML_NAME=html_name, |
1326 NAME=info.declared_name, | 1304 NAME=info.declared_name, |
(...skipping 19 matching lines...) Expand all Loading... |
1346 'IFrameElement.contentWindow', | 1324 'IFrameElement.contentWindow', |
1347 'Window.document', | 1325 'Window.document', |
1348 'Window.top', | 1326 'Window.top', |
1349 'Window.location', | 1327 'Window.location', |
1350 'Window.open', | 1328 'Window.open', |
1351 'IDBDatabase.transaction', | 1329 'IDBDatabase.transaction', |
1352 ]) | 1330 ]) |
1353 | 1331 |
1354 # ------------------------------------------------------------------------------ | 1332 # ------------------------------------------------------------------------------ |
1355 | 1333 |
1356 class HtmlFrogSystem(HtmlSystem): | 1334 class HtmlFrogSystem(System): |
1357 | 1335 |
1358 def __init__(self, templates, database, emitters, output_dir): | 1336 def __init__(self, templates, database, emitters, output_dir): |
1359 super(HtmlFrogSystem, self).__init__( | 1337 super(HtmlFrogSystem, self).__init__( |
1360 templates, database, emitters, output_dir) | 1338 templates, database, emitters, output_dir) |
1361 | 1339 |
1362 def ImplementationGenerator(self, interface): | 1340 def ImplementationGenerator(self, interface): |
1363 return HtmlFrogClassGenerator(self, interface) | 1341 return HtmlFrogClassGenerator(self, interface) |
1364 | 1342 |
1365 def GenerateLibraries(self, dart_files): | 1343 def GenerateLibraries(self, dart_files): |
1366 self._GenerateLibFile( | 1344 self._GenerateLibFile( |
(...skipping 22 matching lines...) Expand all Loading... |
1389 Collect(database.GetInterface(parent.type.id), | 1367 Collect(database.GetInterface(parent.type.id), |
1390 seen, collected) | 1368 seen, collected) |
1391 | 1369 |
1392 inheritance_closure = {} | 1370 inheritance_closure = {} |
1393 for interface in database.GetInterfaces(): | 1371 for interface in database.GetInterfaces(): |
1394 seen = set() | 1372 seen = set() |
1395 collected = [] | 1373 collected = [] |
1396 Collect(interface, seen, collected) | 1374 Collect(interface, seen, collected) |
1397 inheritance_closure[interface.id] = collected | 1375 inheritance_closure[interface.id] = collected |
1398 return inheritance_closure | 1376 return inheritance_closure |
OLD | NEW |