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