Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: lib/html/scripts/generator.py

Issue 11065042: Introduce ListLikeIDLTypeInfo as a replacement for nativified_classes table. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/html/scripts/htmlrenamer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import copy 9 import copy
10 import re 10 import re
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 626
627 def narrow_dart_type(self): 627 def narrow_dart_type(self):
628 return self.dart_type() 628 return self.dart_type()
629 629
630 def interface_name(self): 630 def interface_name(self):
631 raise NotImplementedError() 631 raise NotImplementedError()
632 632
633 def implementation_name(self): 633 def implementation_name(self):
634 raise NotImplementedError() 634 raise NotImplementedError()
635 635
636 def has_generated_interface(self):
637 raise NotImplementedError()
638
636 def native_type(self): 639 def native_type(self):
637 return self._data.native_type or self._idl_type 640 return self._data.native_type or self._idl_type
638 641
639 def bindings_class(self): 642 def bindings_class(self):
640 return 'Dart%s' % self.idl_type() 643 return 'Dart%s' % self.idl_type()
641 644
642 def vector_to_dart_template_parameter(self): 645 def vector_to_dart_template_parameter(self):
643 return self.bindings_class() 646 return self.bindings_class()
644 647
645 def requires_v8_scope(self): 648 def requires_v8_scope(self):
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 718
716 class InterfaceIDLTypeInfo(IDLTypeInfo): 719 class InterfaceIDLTypeInfo(IDLTypeInfo):
717 def __init__(self, idl_type, data, dart_interface_name): 720 def __init__(self, idl_type, data, dart_interface_name):
718 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) 721 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data)
719 self._dart_interface_name = dart_interface_name 722 self._dart_interface_name = dart_interface_name
720 723
721 def dart_type(self): 724 def dart_type(self):
722 return self._data.dart_type or self._dart_interface_name 725 return self._data.dart_type or self._dart_interface_name
723 726
724 def narrow_dart_type(self): 727 def narrow_dart_type(self):
725 # TODO(podivilov): introduce ListLikeIDLTypeInfo and remove this hack.
726 if self._data.suppress_public_interface:
727 return ImplementationClassNameForInterfaceName(self.idl_type())
728 # TODO(podivilov): only primitive and collection types should override 728 # TODO(podivilov): only primitive and collection types should override
729 # dart_type. 729 # dart_type.
730 if self._data.dart_type != None: 730 if self._data.dart_type != None:
731 return self.dart_type() 731 return self.dart_type()
732 if IsPureInterface(self.idl_type()): 732 if IsPureInterface(self.idl_type()):
733 return self.idl_type() 733 return self.idl_type()
734 return self.implementation_name() 734 return self.implementation_name()
735 735
736 def interface_name(self): 736 def interface_name(self):
737 return self._dart_interface_name 737 return self._dart_interface_name
738 738
739 def implementation_name(self): 739 def implementation_name(self):
740 # TODO(podivilov): introduce ListLikeIDLTypeInfo and remove this hack.
741 if self._data.suppress_public_interface:
742 return ImplementationClassNameForInterfaceName(self.idl_type())
743 return ImplementationClassNameForInterfaceName(self._dart_interface_name) 740 return ImplementationClassNameForInterfaceName(self._dart_interface_name)
744 741
742 def has_generated_interface(self):
743 return True
744
745 745
746 class CallbackIDLTypeInfo(IDLTypeInfo): 746 class CallbackIDLTypeInfo(IDLTypeInfo):
747 def __init__(self, idl_type, data): 747 def __init__(self, idl_type, data):
748 super(CallbackIDLTypeInfo, self).__init__(idl_type, data) 748 super(CallbackIDLTypeInfo, self).__init__(idl_type, data)
749 749
750 750
751 # Type info for DOM types that are converted to dart lists and therefore whose
752 # actual interface generation should be suppressed. For type information, we
753 # still generate the implementations though, so these types should not be
754 # suppressed entirely.
755 class ListLikeIDLTypeInfo(IDLTypeInfo):
756 def __init__(self, idl_type, data, item_info):
757 super(ListLikeIDLTypeInfo, self).__init__(idl_type, data)
758 self._item_info = item_info
759
760 def dart_type(self):
761 return 'List<%s>' % self._item_info.dart_type()
762
763 def narrow_dart_type(self):
764 if self.has_generated_interface():
765 return self.dart_type()
766 return ImplementationClassNameForInterfaceName(self.idl_type())
767
768 def interface_name(self):
769 if self.has_generated_interface():
770 return self.idl_type()
771 return self.dart_type()
772
773 def implementation_name(self):
774 return ImplementationClassNameForInterfaceName(self.idl_type())
775
776 def has_generated_interface(self):
777 # Don't generate interfaces for list-like types.
778 # TODO(podivilov): why NodeList is special? Is it indeed a list-like type
779 # or should just implement sequence<Node>?
780 return self.idl_type() == 'NodeList'
781
782
751 class SequenceIDLTypeInfo(IDLTypeInfo): 783 class SequenceIDLTypeInfo(IDLTypeInfo):
752 def __init__(self, idl_type, data, item_info): 784 def __init__(self, idl_type, data, item_info):
753 super(SequenceIDLTypeInfo, self).__init__(idl_type, data) 785 super(SequenceIDLTypeInfo, self).__init__(idl_type, data)
754 self._item_info = item_info 786 self._item_info = item_info
755 787
756 def dart_type(self): 788 def dart_type(self):
757 return 'List<%s>' % self._item_info.dart_type() 789 return 'List<%s>' % self._item_info.dart_type()
758 790
759 def interface_name(self): 791 def interface_name(self):
760 return self.dart_type() 792 return self.dart_type()
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 def argument_expression(self, name, interface_name): 901 def argument_expression(self, name, interface_name):
870 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name 902 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name
871 903
872 904
873 class TypeData(object): 905 class TypeData(object):
874 def __init__(self, clazz, dart_type=None, native_type=None, 906 def __init__(self, clazz, dart_type=None, native_type=None,
875 custom_to_dart=None, custom_to_native=None, 907 custom_to_dart=None, custom_to_native=None,
876 conversion_includes=None, 908 conversion_includes=None,
877 webcore_getter_name='getAttribute', 909 webcore_getter_name='getAttribute',
878 webcore_setter_name='setAttribute', 910 webcore_setter_name='setAttribute',
879 requires_v8_scope=False, suppress_public_interface=False): 911 requires_v8_scope=False,
880 """Constructor. 912 item_type=None):
881 Arguments:
882 - suppress_public_interface is True if we are converting a DOM type to a
883 built-in Dart type in which case we do not want to generate the new
884 interface in the library (FooList -> List<Foo> for example) but we still
885 generate the underlying implementation classes."""
886 self.clazz = clazz 913 self.clazz = clazz
887 self.dart_type = dart_type 914 self.dart_type = dart_type
888 self.native_type = native_type 915 self.native_type = native_type
889 self.custom_to_dart = custom_to_dart 916 self.custom_to_dart = custom_to_dart
890 self.custom_to_native = custom_to_native 917 self.custom_to_native = custom_to_native
891 self.conversion_includes = conversion_includes 918 self.conversion_includes = conversion_includes
892 self.webcore_getter_name = webcore_getter_name 919 self.webcore_getter_name = webcore_getter_name
893 self.webcore_setter_name = webcore_setter_name 920 self.webcore_setter_name = webcore_setter_name
894 self.requires_v8_scope = requires_v8_scope 921 self.requires_v8_scope = requires_v8_scope
895 self.suppress_public_interface = suppress_public_interface 922 self.item_type = item_type
896 923
897 924
898 _idl_type_registry = { 925 _idl_type_registry = {
899 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', 926 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool',
900 webcore_getter_name='hasAttribute', 927 webcore_getter_name='hasAttribute',
901 webcore_setter_name='setBooleanAttribute'), 928 webcore_setter_name='setBooleanAttribute'),
902 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 929 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
903 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 930 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
904 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 931 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
905 'unsigned short': TypeData(clazz='Primitive', dart_type='int', 932 'unsigned short': TypeData(clazz='Primitive', dart_type='int',
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 # the documentation, the user is made aware that only a limited subset of 966 # the documentation, the user is made aware that only a limited subset of
940 # serializable types are actually permitted. 967 # serializable types are actually permitted.
941 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='Dynamic'), 968 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='Dynamic'),
942 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} 969 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool}
943 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce 970 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce
944 'WebKitFlags': TypeData(clazz='Primitive', dart_type='Object'), 971 'WebKitFlags': TypeData(clazz='Primitive', dart_type='Object'),
945 972
946 'sequence': TypeData(clazz='Primitive', dart_type='List'), 973 'sequence': TypeData(clazz='Primitive', dart_type='List'),
947 'void': TypeData(clazz='Primitive', dart_type='void'), 974 'void': TypeData(clazz='Primitive', dart_type='void'),
948 975
949 'WebKitAnimationList': TypeData(clazz='Interface',
950 dart_type='List<Animation>', suppress_public_interface=True),
951 'ClientRectList': TypeData(clazz='Interface', dart_type='List<ClientRect>',
952 suppress_public_interface=True),
953 'CSSRuleList': TypeData(clazz='Interface', dart_type='List<CSSRule>',
954 suppress_public_interface=True),
955 'CSSValueList': TypeData(clazz='Interface', dart_type='List<CSSValue>',
956 suppress_public_interface=True),
957 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ), 976 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ),
958 'DOMException': TypeData(clazz='Interface', native_type='DOMCoreException'), 977 'DOMException': TypeData(clazz='Interface', native_type='DOMCoreException'),
959 'DOMStringList': TypeData(clazz='Interface', dart_type='List<String>', custo m_to_native=True), 978 'DOMStringList': TypeData(clazz='Interface', dart_type='List<String>', custo m_to_native=True),
960 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') , 979 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') ,
961 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True), 980 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True),
962 'Element': TypeData(clazz='Interface', custom_to_dart=True), 981 'Element': TypeData(clazz='Interface', custom_to_dart=True),
963 'EntryArray': TypeData(clazz='Interface', dart_type='List<Entry>',
964 suppress_public_interface=True),
965 'EntryArraySync': TypeData(clazz='Interface',
966 dart_type='List<EntrySync>', suppress_public_interface=True),
967 'EventListener': TypeData(clazz='Interface', custom_to_native=True), 982 'EventListener': TypeData(clazz='Interface', custom_to_native=True),
968 'EventTarget': TypeData(clazz='Interface', custom_to_native=True), 983 'EventTarget': TypeData(clazz='Interface', custom_to_native=True),
969 'FileList': TypeData(clazz='Interface', dart_type='List<File>',
970 suppress_public_interface=True),
971 'GamepadList': TypeData(clazz='Interface', dart_type='List<Gamepad>',
972 suppress_public_interface=True),
973 'HTMLElement': TypeData(clazz='Interface', custom_to_dart=True), 984 'HTMLElement': TypeData(clazz='Interface', custom_to_dart=True),
974 'IDBAny': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True), 985 'IDBAny': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True),
975 'IDBKey': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True), 986 'IDBKey': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True),
976 'MediaStreamList': TypeData(clazz='Interface',
977 dart_type='List<MediaStream>', suppress_public_interface=True),
978 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer. 987 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer.
979 native_type='MutationRecordArray', dart_type='List<MutationRecord>'), 988 native_type='MutationRecordArray', dart_type='List<MutationRecord>'),
980 'NodeList': TypeData(clazz='Interface', dart_type='List<Node>',
981 suppress_public_interface=False),
982 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']), 989 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']),
983 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True), 990 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True),
984 'SVGElementInstanceList': TypeData(clazz='Interface', 991
985 dart_type='List<SVGElementInstance>', suppress_public_interface=True), 992 'ClientRectList': TypeData(clazz='ListLike', item_type='ClientRect'),
986 'SpeechInputResultList': TypeData(clazz='Interface', 993 'CSSRuleList': TypeData(clazz='ListLike', item_type='CSSRule'),
987 dart_type='List<SpeechInputResult>', suppress_public_interface=True), 994 'CSSValueList': TypeData(clazz='ListLike', item_type='CSSValue'),
988 'SpeechRecognitionResultList': TypeData(clazz='Interface', 995 'EntryArray': TypeData(clazz='ListLike', item_type='Entry'),
989 dart_type='List<SpeechRecognitionResult>', 996 'EntryArraySync': TypeData(clazz='ListLike', item_type='EntrySync'),
990 suppress_public_interface=True), 997 'FileList': TypeData(clazz='ListLike', item_type='File'),
991 'StyleSheetList': TypeData(clazz='Interface', 998 'GamepadList': TypeData(clazz='ListLike', item_type='Gamepad'),
992 dart_type='List<StyleSheet>', suppress_public_interface=True), 999 'MediaStreamList': TypeData(clazz='ListLike', item_type='MediaStream'),
1000 'NodeList': TypeData(clazz='ListLike', item_type='Node'),
1001 'SVGElementInstanceList': TypeData(clazz='ListLike',
1002 item_type='SVGElementInstance'),
1003 'SpeechInputResultList': TypeData(clazz='ListLike',
1004 item_type='SpeechInputResult'),
1005 'SpeechRecognitionResultList': TypeData(clazz='ListLike',
1006 item_type='SpeechRecognitionResult'),
1007 'StyleSheetList': TypeData(clazz='ListLike', item_type='StyleSheet'),
1008 'WebKitAnimationList': TypeData(clazz='ListLike',
1009 item_type='WebKitAnimation'),
993 1010
994 'SVGAngle': TypeData(clazz='SVGTearOff'), 1011 'SVGAngle': TypeData(clazz='SVGTearOff'),
995 'SVGLength': TypeData(clazz='SVGTearOff'), 1012 'SVGLength': TypeData(clazz='SVGTearOff'),
996 'SVGLengthList': TypeData(clazz='SVGTearOff'), 1013 'SVGLengthList': TypeData(clazz='SVGTearOff'),
997 'SVGMatrix': TypeData(clazz='SVGTearOff'), 1014 'SVGMatrix': TypeData(clazz='SVGTearOff'),
998 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'), 1015 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'),
999 'SVGNumberList': TypeData(clazz='SVGTearOff'), 1016 'SVGNumberList': TypeData(clazz='SVGTearOff'),
1000 'SVGPathSegList': TypeData(clazz='SVGTearOff', native_type='SVGPathSegListPr opertyTearOff'), 1017 'SVGPathSegList': TypeData(clazz='SVGTearOff', native_type='SVGPathSegListPr opertyTearOff'),
1001 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'), 1018 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'),
1002 'SVGPointList': TypeData(clazz='SVGTearOff'), 1019 'SVGPointList': TypeData(clazz='SVGTearOff'),
1003 'SVGPreserveAspectRatio': TypeData(clazz='SVGTearOff'), 1020 'SVGPreserveAspectRatio': TypeData(clazz='SVGTearOff'),
1004 'SVGRect': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Floa tRect>'), 1021 'SVGRect': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Floa tRect>'),
1005 'SVGStringList': TypeData(clazz='SVGTearOff', native_type='SVGStaticListProp ertyTearOff<SVGStringList>'), 1022 'SVGStringList': TypeData(clazz='SVGTearOff', native_type='SVGStaticListProp ertyTearOff<SVGStringList>'),
1006 'SVGTransform': TypeData(clazz='SVGTearOff'), 1023 'SVGTransform': TypeData(clazz='SVGTearOff'),
1007 'SVGTransformList': TypeData(clazz='SVGTearOff', native_type='SVGTransformLi stPropertyTearOff'), 1024 'SVGTransformList': TypeData(clazz='SVGTearOff', native_type='SVGTransformLi stPropertyTearOff'),
1008 } 1025 }
1009 1026
1010 # A list constructed of DOM types that are converted to built-in dart types
1011 # (like Lists) and therefore whose actual interface generation should be
1012 # suppressed. (For type information, we still generate the implementations
1013 # though, so these types should not be suppressed entirely.)
1014 nativified_classes = {}
1015 for key in _idl_type_registry:
1016 value = _idl_type_registry[key]
1017 if value.suppress_public_interface:
1018 nativified_classes[value.dart_type] = key
1019 html_interface_renames[key] = value.dart_type
1020
1021 _svg_supplemental_includes = [ 1027 _svg_supplemental_includes = [
1022 '"SVGAnimatedPropertyTearOff.h"', 1028 '"SVGAnimatedPropertyTearOff.h"',
1023 '"SVGAnimatedListPropertyTearOff.h"', 1029 '"SVGAnimatedListPropertyTearOff.h"',
1024 '"SVGStaticListPropertyTearOff.h"', 1030 '"SVGStaticListPropertyTearOff.h"',
1025 '"SVGAnimatedListPropertyTearOff.h"', 1031 '"SVGAnimatedListPropertyTearOff.h"',
1026 '"SVGTransformListPropertyTearOff.h"', 1032 '"SVGTransformListPropertyTearOff.h"',
1027 '"SVGPathSegListPropertyTearOff.h"', 1033 '"SVGPathSegListPropertyTearOff.h"',
1028 ] 1034 ]
1029 1035
1030 class TypeRegistry(object): 1036 class TypeRegistry(object):
(...skipping 21 matching lines...) Expand all
1052 if not type_name in _idl_type_registry: 1058 if not type_name in _idl_type_registry:
1053 interface = self._database.GetInterface(type_name) 1059 interface = self._database.GetInterface(type_name)
1054 if 'Callback' in interface.ext_attrs: 1060 if 'Callback' in interface.ext_attrs:
1055 return CallbackIDLTypeInfo(type_name, TypeData('Callback')) 1061 return CallbackIDLTypeInfo(type_name, TypeData('Callback'))
1056 return InterfaceIDLTypeInfo( 1062 return InterfaceIDLTypeInfo(
1057 type_name, 1063 type_name,
1058 TypeData('Interface'), 1064 TypeData('Interface'),
1059 self._renamer.RenameInterface(interface)) 1065 self._renamer.RenameInterface(interface))
1060 1066
1061 type_data = _idl_type_registry.get(type_name) 1067 type_data = _idl_type_registry.get(type_name)
1068
1062 if type_data.clazz == 'Interface': 1069 if type_data.clazz == 'Interface':
1063 if self._database.HasInterface(type_name): 1070 if self._database.HasInterface(type_name):
1064 dart_interface_name = self._renamer.RenameInterface( 1071 dart_interface_name = self._renamer.RenameInterface(
1065 self._database.GetInterface(type_name)) 1072 self._database.GetInterface(type_name))
1066 else: 1073 else:
1067 dart_interface_name = type_name 1074 dart_interface_name = type_name
1068 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) 1075 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name)
1069 1076
1077 if type_data.clazz == 'ListLike':
1078 return ListLikeIDLTypeInfo(type_name, type_data, self.TypeInfo(type_data.i tem_type))
1079
1070 class_name = '%sIDLTypeInfo' % type_data.clazz 1080 class_name = '%sIDLTypeInfo' % type_data.clazz
1071 return globals()[class_name](type_name, type_data) 1081 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « no previous file | lib/html/scripts/htmlrenamer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698