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

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

Issue 10941047: Don't generate FooList if it behaves like List<Foo> exactly. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
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 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 def argument_expression(self, name, interface_name): 801 def argument_expression(self, name, interface_name):
802 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name 802 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name
803 803
804 804
805 class TypeData(object): 805 class TypeData(object):
806 def __init__(self, clazz, dart_type=None, native_type=None, 806 def __init__(self, clazz, dart_type=None, native_type=None,
807 custom_to_dart=None, custom_to_native=None, 807 custom_to_dart=None, custom_to_native=None,
808 conversion_includes=None, 808 conversion_includes=None,
809 webcore_getter_name='getAttribute', 809 webcore_getter_name='getAttribute',
810 webcore_setter_name='setAttribute', 810 webcore_setter_name='setAttribute',
811 requires_v8_scope=False): 811 requires_v8_scope=False, suppress_public_interface=False):
812 """Constructor.
813 Arguments:
814 - suppress_public_interface is True if we are converting a DOM type to a
815 built-in Dart type in which case we do not want to generate the new
816 interface in the library (FooList -> List<Foo> for example) but we still
817 generate the underlying implementation classes."""
812 self.clazz = clazz 818 self.clazz = clazz
813 self.dart_type = dart_type 819 self.dart_type = dart_type
814 self.native_type = native_type 820 self.native_type = native_type
815 self.custom_to_dart = custom_to_dart 821 self.custom_to_dart = custom_to_dart
816 self.custom_to_native = custom_to_native 822 self.custom_to_native = custom_to_native
817 self.conversion_includes = conversion_includes 823 self.conversion_includes = conversion_includes
818 self.webcore_getter_name = webcore_getter_name 824 self.webcore_getter_name = webcore_getter_name
819 self.webcore_setter_name = webcore_setter_name 825 self.webcore_setter_name = webcore_setter_name
820 self.requires_v8_scope = requires_v8_scope 826 self.requires_v8_scope = requires_v8_scope
827 self.suppress_public_interface = suppress_public_interface
821 828
822 829
823 _idl_type_registry = { 830 _idl_type_registry = {
824 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', 831 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool',
825 webcore_getter_name='hasAttribute', 832 webcore_getter_name='hasAttribute',
826 webcore_setter_name='setBooleanAttribute'), 833 webcore_setter_name='setBooleanAttribute'),
827 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 834 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
828 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 835 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
829 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 836 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
830 'unsigned short': TypeData(clazz='Primitive', dart_type='int', 837 'unsigned short': TypeData(clazz='Primitive', dart_type='int',
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 # the documentation, the user is made aware that only a limited subset of 871 # the documentation, the user is made aware that only a limited subset of
865 # serializable types are actually permitted. 872 # serializable types are actually permitted.
866 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='Dynamic'), 873 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='Dynamic'),
867 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} 874 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool}
868 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce 875 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce
869 'WebKitFlags': TypeData(clazz='Primitive', dart_type='Object'), 876 'WebKitFlags': TypeData(clazz='Primitive', dart_type='Object'),
870 877
871 'sequence': TypeData(clazz='Primitive', dart_type='List'), 878 'sequence': TypeData(clazz='Primitive', dart_type='List'),
872 'void': TypeData(clazz='Primitive', dart_type='void'), 879 'void': TypeData(clazz='Primitive', dart_type='void'),
873 880
881 'ClientRectList': TypeData(clazz='Interface', dart_type='List<ClientRect>',
882 custom_to_native=True, suppress_public_interface=True),
883 'CSSRuleList': TypeData(clazz='Interface', dart_type='List<CSSRule>',
884 custom_to_native=True, suppress_public_interface=True),
885 'CSSValueList': TypeData(clazz='Interface', dart_type='List<CSSValue>',
886 custom_to_native=True, suppress_public_interface=True),
874 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ), 887 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ),
875 'DOMException': TypeData(clazz='Interface', native_type='DOMCoreException'), 888 'DOMException': TypeData(clazz='Interface', native_type='DOMCoreException'),
876 'DOMStringList': TypeData(clazz='Interface', dart_type='List<String>', custo m_to_native=True), 889 'DOMStringList': TypeData(clazz='Interface', dart_type='List<String>', custo m_to_native=True),
877 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') , 890 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') ,
878 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True), 891 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True),
879 'Element': TypeData(clazz='Interface', custom_to_dart=True), 892 'Element': TypeData(clazz='Interface', custom_to_dart=True),
893 'EntryArray': TypeData(clazz='Interface', dart_type='List<EntryArray>',
894 custom_to_native=True, suppress_public_interface=True),
895 'EntryArraySync': TypeData(clazz='Interface',
896 dart_type='List<EntryArraySync>', custom_to_native=True,
897 suppress_public_interface=True),
880 'EventListener': TypeData(clazz='Interface', custom_to_native=True), 898 'EventListener': TypeData(clazz='Interface', custom_to_native=True),
881 'EventTarget': TypeData(clazz='Interface', custom_to_native=True), 899 'EventTarget': TypeData(clazz='Interface', custom_to_native=True),
900 'FileList': TypeData(clazz='Interface', dart_type='List<File>',
901 custom_to_native=True, suppress_public_interface=True),
902 'GamepadList': TypeData(clazz='Interface', dart_type='List<Gamepad>',
903 custom_to_native=True, suppress_public_interface=True),
882 'HTMLElement': TypeData(clazz='Interface', custom_to_dart=True), 904 'HTMLElement': TypeData(clazz='Interface', custom_to_dart=True),
883 'IDBAny': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True), 905 'IDBAny': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True),
884 'IDBKey': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True), 906 'IDBKey': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True),
907 'MediaStreamList': TypeData(clazz='Interface',
908 dart_type='List<MediaStream>', custom_to_native=True,
909 suppress_public_interface=True),
885 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer. 910 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer.
886 native_type='MutationRecordArray', 911 native_type='MutationRecordArray', dart_type='List<MutationRecord>'),
887 dart_type='List<MutationRecord>'),
888 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']), 912 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']),
889 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True), 913 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True),
914 'SVGElementInstanceList': TypeData(clazz='Interface',
915 dart_type='List<SVGElementInstance>', custom_to_native=True,
916 suppress_public_interface=True),
917 'SpeechInputResultList': TypeData(clazz='Interface',
918 dart_type='List<SpeechInputResult>', custom_to_native=True,
919 suppress_public_interface=True),
920 'SpeechRecognitionResultList': TypeData(clazz='Interface',
921 dart_type='List<SpeechRecognitionResult>', custom_to_native=True,
922 suppress_public_interface=True),
923 'StyleSheetList': TypeData(clazz='Interface',
924 dart_type='List<StyleSheet>', custom_to_native=True,
925 suppress_public_interface=True),
890 926
891 'SVGAngle': TypeData(clazz='SVGTearOff'), 927 'SVGAngle': TypeData(clazz='SVGTearOff'),
892 'SVGLength': TypeData(clazz='SVGTearOff'), 928 'SVGLength': TypeData(clazz='SVGTearOff'),
893 'SVGLengthList': TypeData(clazz='SVGTearOff'), 929 'SVGLengthList': TypeData(clazz='SVGTearOff'),
894 'SVGMatrix': TypeData(clazz='SVGTearOff'), 930 'SVGMatrix': TypeData(clazz='SVGTearOff'),
895 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'), 931 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'),
896 'SVGNumberList': TypeData(clazz='SVGTearOff'), 932 'SVGNumberList': TypeData(clazz='SVGTearOff'),
897 'SVGPathSegList': TypeData(clazz='SVGTearOff', native_type='SVGPathSegListPr opertyTearOff'), 933 'SVGPathSegList': TypeData(clazz='SVGTearOff', native_type='SVGPathSegListPr opertyTearOff'),
898 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'), 934 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'),
899 'SVGPointList': TypeData(clazz='SVGTearOff'), 935 'SVGPointList': TypeData(clazz='SVGTearOff'),
900 'SVGPreserveAspectRatio': TypeData(clazz='SVGTearOff'), 936 'SVGPreserveAspectRatio': TypeData(clazz='SVGTearOff'),
901 'SVGRect': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Floa tRect>'), 937 'SVGRect': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Floa tRect>'),
902 'SVGStringList': TypeData(clazz='SVGTearOff', native_type='SVGStaticListProp ertyTearOff<SVGStringList>'), 938 'SVGStringList': TypeData(clazz='SVGTearOff', native_type='SVGStaticListProp ertyTearOff<SVGStringList>'),
903 'SVGTransform': TypeData(clazz='SVGTearOff'), 939 'SVGTransform': TypeData(clazz='SVGTearOff'),
904 'SVGTransformList': TypeData(clazz='SVGTearOff', native_type='SVGTransformLi stPropertyTearOff'), 940 'SVGTransformList': TypeData(clazz='SVGTearOff', native_type='SVGTransformLi stPropertyTearOff'),
905 } 941 }
906 942
943 # A list constructed of DOM types that are converted to built-in dart types
944 # (like Lists) and therefore whose actual interface generation should be
945 # suppressed. (For type information, we still generate the implementations
946 # though, so these types should not be suppressed entirely.)
947 nativified_classes = {}
vsm 2012/09/21 22:43:12 How about calling this suppressed_classes?
948 for key in _idl_type_registry:
949 value = _idl_type_registry[key]
950 if value.suppress_public_interface:
951 nativified_classes[value.dart_type] = key
952
907 _svg_supplemental_includes = [ 953 _svg_supplemental_includes = [
908 '"SVGAnimatedPropertyTearOff.h"', 954 '"SVGAnimatedPropertyTearOff.h"',
909 '"SVGAnimatedListPropertyTearOff.h"', 955 '"SVGAnimatedListPropertyTearOff.h"',
910 '"SVGStaticListPropertyTearOff.h"', 956 '"SVGStaticListPropertyTearOff.h"',
911 '"SVGAnimatedListPropertyTearOff.h"', 957 '"SVGAnimatedListPropertyTearOff.h"',
912 '"SVGTransformListPropertyTearOff.h"', 958 '"SVGTransformListPropertyTearOff.h"',
913 '"SVGPathSegListPropertyTearOff.h"', 959 '"SVGPathSegListPropertyTearOff.h"',
914 ] 960 ]
915 961
916 class TypeRegistry(object): 962 class TypeRegistry(object):
(...skipping 22 matching lines...) Expand all
939 if match: 985 if match:
940 if type_name == 'DOMString[]': 986 if type_name == 'DOMString[]':
941 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring')) 987 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring'))
942 item_info = self.TypeInfo(match.group(1) or match.group(2)) 988 item_info = self.TypeInfo(match.group(1) or match.group(2))
943 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) 989 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info)
944 if not type_name in _idl_type_registry: 990 if not type_name in _idl_type_registry:
945 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) 991 return InterfaceIDLTypeInfo(type_name, TypeData('Interface'))
946 type_data = _idl_type_registry.get(type_name) 992 type_data = _idl_type_registry.get(type_name)
947 class_name = '%sIDLTypeInfo' % type_data.clazz 993 class_name = '%sIDLTypeInfo' % type_data.clazz
948 return globals()[class_name](type_name, type_data) 994 return globals()[class_name](type_name, type_data)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698