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

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 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 614
615 def narrow_dart_type(self): 615 def narrow_dart_type(self):
616 return self.dart_type() 616 return self.dart_type()
617 617
618 def interface_name(self): 618 def interface_name(self):
619 raise NotImplementedError() 619 raise NotImplementedError()
620 620
621 def implementation_name(self): 621 def implementation_name(self):
622 raise NotImplementedError() 622 raise NotImplementedError()
623 623
624 def has_generated_interface(self):
625 raise NotImplementedError()
626
624 def native_type(self): 627 def native_type(self):
625 return self._data.native_type or self._idl_type 628 return self._data.native_type or self._idl_type
626 629
627 def bindings_class(self): 630 def bindings_class(self):
628 return 'Dart%s' % self.idl_type() 631 return 'Dart%s' % self.idl_type()
629 632
630 def vector_to_dart_template_parameter(self): 633 def vector_to_dart_template_parameter(self):
631 return self.bindings_class() 634 return self.bindings_class()
632 635
633 def requires_v8_scope(self): 636 def requires_v8_scope(self):
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 706
704 class InterfaceIDLTypeInfo(IDLTypeInfo): 707 class InterfaceIDLTypeInfo(IDLTypeInfo):
705 def __init__(self, idl_type, data, dart_interface_name): 708 def __init__(self, idl_type, data, dart_interface_name):
706 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) 709 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data)
707 self._dart_interface_name = dart_interface_name 710 self._dart_interface_name = dart_interface_name
708 711
709 def dart_type(self): 712 def dart_type(self):
710 return self._data.dart_type or self._dart_interface_name 713 return self._data.dart_type or self._dart_interface_name
711 714
712 def narrow_dart_type(self): 715 def narrow_dart_type(self):
713 # TODO(podivilov): introduce ListLikeIDLTypeInfo and remove this hack.
714 if self._data.suppress_public_interface:
715 return ImplementationClassNameForInterfaceName(self.idl_type())
716 # TODO(podivilov): only primitive and collection types should override 716 # TODO(podivilov): only primitive and collection types should override
717 # dart_type. 717 # dart_type.
718 if self._data.dart_type != None: 718 if self._data.dart_type != None:
719 return self.dart_type() 719 return self.dart_type()
720 if IsPureInterface(self.idl_type()): 720 if IsPureInterface(self.idl_type()):
721 return self.idl_type() 721 return self.idl_type()
722 return self.implementation_name() 722 return self.implementation_name()
723 723
724 def interface_name(self): 724 def interface_name(self):
725 return self._dart_interface_name 725 return self._dart_interface_name
726 726
727 def implementation_name(self): 727 def implementation_name(self):
728 # TODO(podivilov): introduce ListLikeIDLTypeInfo and remove this hack.
729 if self._data.suppress_public_interface:
730 return ImplementationClassNameForInterfaceName(self.idl_type())
731 return ImplementationClassNameForInterfaceName(self._dart_interface_name) 728 return ImplementationClassNameForInterfaceName(self._dart_interface_name)
732 729
730 def has_generated_interface(self):
731 return True
732
733 733
734 class CallbackIDLTypeInfo(IDLTypeInfo): 734 class CallbackIDLTypeInfo(IDLTypeInfo):
735 def __init__(self, idl_type, data): 735 def __init__(self, idl_type, data):
736 super(CallbackIDLTypeInfo, self).__init__(idl_type, data) 736 super(CallbackIDLTypeInfo, self).__init__(idl_type, data)
737 737
738 738
739 # Type info for DOM types that are converted to built-in dart types
Anton Muhin 2012/10/10 07:44:00 comment is somewhat at odds with the name of the c
podivilov 2012/10/10 13:24:06 Done.
740 # (like Lists) and therefore whose actual interface generation should be
741 # suppressed. (For type information, we still generate the implementations
742 # though, so these types should not be suppressed entirely.)
743 class ListLikeIDLTypeInfo(IDLTypeInfo):
744 def __init__(self, idl_type, data, item_info):
745 super(ListLikeIDLTypeInfo, self).__init__(idl_type, data)
746 self._item_info = item_info
747
748 def dart_type(self):
749 return 'List<%s>' % self._item_info.dart_type()
750
751 def narrow_dart_type(self):
752 return ImplementationClassNameForInterfaceName(self.idl_type())
753
754 def interface_name(self):
755 # TODO(podivilov): why NodeList is special? Is it indeed a list-like type
Emily Fortuna 2012/10/05 18:26:08 NodeList is special because it is fully list-like
podivilov 2012/10/05 19:59:19 Here's what I see in generated files: abstract c
756 # or should just implement sequence<Node>?
757 if self.idl_type() == 'NodeList':
Anton Muhin 2012/10/10 07:44:00 if not has_generated_interface(): return self.idl_
podivilov 2012/10/10 13:24:06 Done.
758 return self.idl_type()
759 return self.dart_type()
760
761 def implementation_name(self):
762 return ImplementationClassNameForInterfaceName(self.idl_type())
763
764 def has_generated_interface(self):
765 # Don't generate interfaces for list-like types.
766 # TODO(podivilov): why NodeList is special? Is it indeed a list-like type
767 # or should just implement sequence<Node>?
768 return self.idl_type() == 'NodeList'
769
770
739 class SequenceIDLTypeInfo(IDLTypeInfo): 771 class SequenceIDLTypeInfo(IDLTypeInfo):
740 def __init__(self, idl_type, data, item_info): 772 def __init__(self, idl_type, data, item_info):
741 super(SequenceIDLTypeInfo, self).__init__(idl_type, data) 773 super(SequenceIDLTypeInfo, self).__init__(idl_type, data)
742 self._item_info = item_info 774 self._item_info = item_info
743 775
744 def dart_type(self): 776 def dart_type(self):
745 return 'List<%s>' % self._item_info.dart_type() 777 return 'List<%s>' % self._item_info.dart_type()
746 778
747 def interface_name(self): 779 def interface_name(self):
748 return self.dart_type() 780 return self.dart_type()
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 def argument_expression(self, name, interface_name): 889 def argument_expression(self, name, interface_name):
858 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name 890 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name
859 891
860 892
861 class TypeData(object): 893 class TypeData(object):
862 def __init__(self, clazz, dart_type=None, native_type=None, 894 def __init__(self, clazz, dart_type=None, native_type=None,
863 custom_to_dart=None, custom_to_native=None, 895 custom_to_dart=None, custom_to_native=None,
864 conversion_includes=None, 896 conversion_includes=None,
865 webcore_getter_name='getAttribute', 897 webcore_getter_name='getAttribute',
866 webcore_setter_name='setAttribute', 898 webcore_setter_name='setAttribute',
867 requires_v8_scope=False, suppress_public_interface=False): 899 requires_v8_scope=False,
868 """Constructor. 900 item_type=None):
869 Arguments:
870 - suppress_public_interface is True if we are converting a DOM type to a
871 built-in Dart type in which case we do not want to generate the new
872 interface in the library (FooList -> List<Foo> for example) but we still
873 generate the underlying implementation classes."""
874 self.clazz = clazz 901 self.clazz = clazz
875 self.dart_type = dart_type 902 self.dart_type = dart_type
876 self.native_type = native_type 903 self.native_type = native_type
877 self.custom_to_dart = custom_to_dart 904 self.custom_to_dart = custom_to_dart
878 self.custom_to_native = custom_to_native 905 self.custom_to_native = custom_to_native
879 self.conversion_includes = conversion_includes 906 self.conversion_includes = conversion_includes
880 self.webcore_getter_name = webcore_getter_name 907 self.webcore_getter_name = webcore_getter_name
881 self.webcore_setter_name = webcore_setter_name 908 self.webcore_setter_name = webcore_setter_name
882 self.requires_v8_scope = requires_v8_scope 909 self.requires_v8_scope = requires_v8_scope
883 self.suppress_public_interface = suppress_public_interface 910 self.item_type = item_type
884 911
885 912
886 _idl_type_registry = { 913 _idl_type_registry = {
887 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', 914 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool',
888 webcore_getter_name='hasAttribute', 915 webcore_getter_name='hasAttribute',
889 webcore_setter_name='setBooleanAttribute'), 916 webcore_setter_name='setBooleanAttribute'),
890 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 917 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
891 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 918 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
892 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 919 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
893 'unsigned short': TypeData(clazz='Primitive', dart_type='int', 920 'unsigned short': TypeData(clazz='Primitive', dart_type='int',
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 # the documentation, the user is made aware that only a limited subset of 954 # the documentation, the user is made aware that only a limited subset of
928 # serializable types are actually permitted. 955 # serializable types are actually permitted.
929 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='Dynamic'), 956 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='Dynamic'),
930 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} 957 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool}
931 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce 958 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce
932 'WebKitFlags': TypeData(clazz='Primitive', dart_type='Object'), 959 'WebKitFlags': TypeData(clazz='Primitive', dart_type='Object'),
933 960
934 'sequence': TypeData(clazz='Primitive', dart_type='List'), 961 'sequence': TypeData(clazz='Primitive', dart_type='List'),
935 'void': TypeData(clazz='Primitive', dart_type='void'), 962 'void': TypeData(clazz='Primitive', dart_type='void'),
936 963
937 'WebKitAnimationList': TypeData(clazz='Interface',
938 dart_type='List<Animation>', suppress_public_interface=True),
939 'ClientRectList': TypeData(clazz='Interface', dart_type='List<ClientRect>',
940 suppress_public_interface=True),
941 'CSSRuleList': TypeData(clazz='Interface', dart_type='List<CSSRule>',
942 suppress_public_interface=True),
943 'CSSValueList': TypeData(clazz='Interface', dart_type='List<CSSValue>',
944 suppress_public_interface=True),
945 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ), 964 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ),
946 'DOMException': TypeData(clazz='Interface', native_type='DOMCoreException'), 965 'DOMException': TypeData(clazz='Interface', native_type='DOMCoreException'),
947 'DOMStringList': TypeData(clazz='Interface', dart_type='List<String>', custo m_to_native=True), 966 'DOMStringList': TypeData(clazz='Interface', dart_type='List<String>', custo m_to_native=True),
948 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') , 967 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') ,
949 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True), 968 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True),
950 'Element': TypeData(clazz='Interface', custom_to_dart=True), 969 'Element': TypeData(clazz='Interface', custom_to_dart=True),
951 'EntryArray': TypeData(clazz='Interface', dart_type='List<Entry>',
952 suppress_public_interface=True),
953 'EntryArraySync': TypeData(clazz='Interface',
954 dart_type='List<EntrySync>', suppress_public_interface=True),
955 'EventListener': TypeData(clazz='Interface', custom_to_native=True), 970 'EventListener': TypeData(clazz='Interface', custom_to_native=True),
956 'EventTarget': TypeData(clazz='Interface', custom_to_native=True), 971 'EventTarget': TypeData(clazz='Interface', custom_to_native=True),
957 'FileList': TypeData(clazz='Interface', dart_type='List<File>',
958 suppress_public_interface=True),
959 'GamepadList': TypeData(clazz='Interface', dart_type='List<Gamepad>',
960 suppress_public_interface=True),
961 'HTMLElement': TypeData(clazz='Interface', custom_to_dart=True), 972 'HTMLElement': TypeData(clazz='Interface', custom_to_dart=True),
962 'IDBAny': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True), 973 'IDBAny': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True),
963 'IDBKey': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True), 974 'IDBKey': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True),
964 'MediaStreamList': TypeData(clazz='Interface',
965 dart_type='List<MediaStream>', suppress_public_interface=True),
966 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer. 975 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer.
967 native_type='MutationRecordArray', dart_type='List<MutationRecord>'), 976 native_type='MutationRecordArray', dart_type='List<MutationRecord>'),
968 'NodeList': TypeData(clazz='Interface', dart_type='List<Node>',
969 suppress_public_interface=False),
970 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']), 977 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']),
971 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True), 978 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True),
972 'SVGElementInstanceList': TypeData(clazz='Interface', 979
973 dart_type='List<SVGElementInstance>', suppress_public_interface=True), 980 'ClientRectList': TypeData(clazz='ListLike', item_type='ClientRect'),
974 'SpeechInputResultList': TypeData(clazz='Interface', 981 'CSSRuleList': TypeData(clazz='ListLike', item_type='CSSRule'),
975 dart_type='List<SpeechInputResult>', suppress_public_interface=True), 982 'CSSValueList': TypeData(clazz='ListLike', item_type='CSSValue'),
976 'SpeechRecognitionResultList': TypeData(clazz='Interface', 983 'EntryArray': TypeData(clazz='ListLike', item_type='Entry'),
977 dart_type='List<SpeechRecognitionResult>', 984 'EntryArraySync': TypeData(clazz='ListLike', item_type='EntrySync'),
978 suppress_public_interface=True), 985 'FileList': TypeData(clazz='ListLike', item_type='File'),
979 'StyleSheetList': TypeData(clazz='Interface', 986 'GamepadList': TypeData(clazz='ListLike', item_type='Gamepad'),
980 dart_type='List<StyleSheet>', suppress_public_interface=True), 987 'MediaStreamList': TypeData(clazz='ListLike', item_type='MediaStream'),
988 'NodeList': TypeData(clazz='ListLike', item_type='Node'),
989 'SVGElementInstanceList': TypeData(clazz='ListLike',
990 item_type='SVGElementInstance'),
991 'SpeechInputResultList': TypeData(clazz='ListLike',
992 item_type='SpeechInputResult'),
993 'SpeechRecognitionResultList': TypeData(clazz='ListLike',
994 item_type='SpeechRecognitionResult'),
995 'StyleSheetList': TypeData(clazz='ListLike', item_type='StyleSheet'),
996 'WebKitAnimationList': TypeData(clazz='ListLike', item_type='WebKitAnimation '),
Emily Fortuna 2012/10/05 18:26:08 80 char here and at 1065 if you guys are paying at
podivilov 2012/10/05 19:59:19 Yes, we do. Thanks for spotting!
981 997
982 'SVGAngle': TypeData(clazz='SVGTearOff'), 998 'SVGAngle': TypeData(clazz='SVGTearOff'),
983 'SVGLength': TypeData(clazz='SVGTearOff'), 999 'SVGLength': TypeData(clazz='SVGTearOff'),
984 'SVGLengthList': TypeData(clazz='SVGTearOff'), 1000 'SVGLengthList': TypeData(clazz='SVGTearOff'),
985 'SVGMatrix': TypeData(clazz='SVGTearOff'), 1001 'SVGMatrix': TypeData(clazz='SVGTearOff'),
986 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'), 1002 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'),
987 'SVGNumberList': TypeData(clazz='SVGTearOff'), 1003 'SVGNumberList': TypeData(clazz='SVGTearOff'),
988 'SVGPathSegList': TypeData(clazz='SVGTearOff', native_type='SVGPathSegListPr opertyTearOff'), 1004 'SVGPathSegList': TypeData(clazz='SVGTearOff', native_type='SVGPathSegListPr opertyTearOff'),
989 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'), 1005 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'),
990 'SVGPointList': TypeData(clazz='SVGTearOff'), 1006 'SVGPointList': TypeData(clazz='SVGTearOff'),
991 'SVGPreserveAspectRatio': TypeData(clazz='SVGTearOff'), 1007 'SVGPreserveAspectRatio': TypeData(clazz='SVGTearOff'),
992 'SVGRect': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Floa tRect>'), 1008 'SVGRect': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Floa tRect>'),
993 'SVGStringList': TypeData(clazz='SVGTearOff', native_type='SVGStaticListProp ertyTearOff<SVGStringList>'), 1009 'SVGStringList': TypeData(clazz='SVGTearOff', native_type='SVGStaticListProp ertyTearOff<SVGStringList>'),
994 'SVGTransform': TypeData(clazz='SVGTearOff'), 1010 'SVGTransform': TypeData(clazz='SVGTearOff'),
995 'SVGTransformList': TypeData(clazz='SVGTearOff', native_type='SVGTransformLi stPropertyTearOff'), 1011 'SVGTransformList': TypeData(clazz='SVGTearOff', native_type='SVGTransformLi stPropertyTearOff'),
996 } 1012 }
997 1013
998 # A list constructed of DOM types that are converted to built-in dart types
999 # (like Lists) and therefore whose actual interface generation should be
1000 # suppressed. (For type information, we still generate the implementations
1001 # though, so these types should not be suppressed entirely.)
1002 nativified_classes = {}
1003 for key in _idl_type_registry:
1004 value = _idl_type_registry[key]
1005 if value.suppress_public_interface:
1006 nativified_classes[value.dart_type] = key
1007 html_interface_renames[key] = value.dart_type
1008
1009 _svg_supplemental_includes = [ 1014 _svg_supplemental_includes = [
1010 '"SVGAnimatedPropertyTearOff.h"', 1015 '"SVGAnimatedPropertyTearOff.h"',
1011 '"SVGAnimatedListPropertyTearOff.h"', 1016 '"SVGAnimatedListPropertyTearOff.h"',
1012 '"SVGStaticListPropertyTearOff.h"', 1017 '"SVGStaticListPropertyTearOff.h"',
1013 '"SVGAnimatedListPropertyTearOff.h"', 1018 '"SVGAnimatedListPropertyTearOff.h"',
1014 '"SVGTransformListPropertyTearOff.h"', 1019 '"SVGTransformListPropertyTearOff.h"',
1015 '"SVGPathSegListPropertyTearOff.h"', 1020 '"SVGPathSegListPropertyTearOff.h"',
1016 ] 1021 ]
1017 1022
1018 class TypeRegistry(object): 1023 class TypeRegistry(object):
(...skipping 21 matching lines...) Expand all
1040 if not type_name in _idl_type_registry: 1045 if not type_name in _idl_type_registry:
1041 interface = self._database.GetInterface(type_name) 1046 interface = self._database.GetInterface(type_name)
1042 if 'Callback' in interface.ext_attrs: 1047 if 'Callback' in interface.ext_attrs:
1043 return CallbackIDLTypeInfo(type_name, TypeData('Callback')) 1048 return CallbackIDLTypeInfo(type_name, TypeData('Callback'))
1044 return InterfaceIDLTypeInfo( 1049 return InterfaceIDLTypeInfo(
1045 type_name, 1050 type_name,
1046 TypeData('Interface'), 1051 TypeData('Interface'),
1047 self._renamer.RenameInterface(interface)) 1052 self._renamer.RenameInterface(interface))
1048 1053
1049 type_data = _idl_type_registry.get(type_name) 1054 type_data = _idl_type_registry.get(type_name)
1055
1050 if type_data.clazz == 'Interface': 1056 if type_data.clazz == 'Interface':
1051 if self._database.HasInterface(type_name): 1057 if self._database.HasInterface(type_name):
1052 dart_interface_name = self._renamer.RenameInterface( 1058 dart_interface_name = self._renamer.RenameInterface(
1053 self._database.GetInterface(type_name)) 1059 self._database.GetInterface(type_name))
1054 else: 1060 else:
1055 dart_interface_name = type_name 1061 dart_interface_name = type_name
1056 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) 1062 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name)
1057 1063
1064 if type_data.clazz == 'ListLike':
1065 return ListLikeIDLTypeInfo(type_name, type_data, self.TypeInfo(type_data.i tem_type))
1066
1058 class_name = '%sIDLTypeInfo' % type_data.clazz 1067 class_name = '%sIDLTypeInfo' % type_data.clazz
1059 return globals()[class_name](type_name, type_data) 1068 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