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

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

Issue 10981005: Revert r12808. (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
« no previous file with comments | « lib/html/idl/dart/dart.idl ('k') | 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
11 from htmlrenamer import html_interface_renames
12 11
13 _pure_interfaces = set([ 12 _pure_interfaces = set([
14 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. 13 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>.
15 'DOMStringMap', 14 'DOMStringMap',
16 'ElementTimeControl', 15 'ElementTimeControl',
17 'ElementTraversal', 16 'ElementTraversal',
18 'MediaQueryListListener', 17 'MediaQueryListListener',
19 'NodeSelector', 18 'NodeSelector',
20 'SVGExternalResourcesRequired', 19 'SVGExternalResourcesRequired',
21 'SVGFilterPrimitiveStandardAttributes', 20 'SVGFilterPrimitiveStandardAttributes',
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 def argument_expression(self, name, interface_name): 801 def argument_expression(self, name, interface_name):
803 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name 802 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name
804 803
805 804
806 class TypeData(object): 805 class TypeData(object):
807 def __init__(self, clazz, dart_type=None, native_type=None, 806 def __init__(self, clazz, dart_type=None, native_type=None,
808 custom_to_dart=None, custom_to_native=None, 807 custom_to_dart=None, custom_to_native=None,
809 conversion_includes=None, 808 conversion_includes=None,
810 webcore_getter_name='getAttribute', 809 webcore_getter_name='getAttribute',
811 webcore_setter_name='setAttribute', 810 webcore_setter_name='setAttribute',
812 requires_v8_scope=False, suppress_public_interface=False): 811 requires_v8_scope=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."""
819 self.clazz = clazz 812 self.clazz = clazz
820 self.dart_type = dart_type 813 self.dart_type = dart_type
821 self.native_type = native_type 814 self.native_type = native_type
822 self.custom_to_dart = custom_to_dart 815 self.custom_to_dart = custom_to_dart
823 self.custom_to_native = custom_to_native 816 self.custom_to_native = custom_to_native
824 self.conversion_includes = conversion_includes 817 self.conversion_includes = conversion_includes
825 self.webcore_getter_name = webcore_getter_name 818 self.webcore_getter_name = webcore_getter_name
826 self.webcore_setter_name = webcore_setter_name 819 self.webcore_setter_name = webcore_setter_name
827 self.requires_v8_scope = requires_v8_scope 820 self.requires_v8_scope = requires_v8_scope
828 self.suppress_public_interface = suppress_public_interface
829 821
830 822
831 _idl_type_registry = { 823 _idl_type_registry = {
832 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', 824 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool',
833 webcore_getter_name='hasAttribute', 825 webcore_getter_name='hasAttribute',
834 webcore_setter_name='setBooleanAttribute'), 826 webcore_setter_name='setBooleanAttribute'),
835 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 827 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
836 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 828 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
837 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 829 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
838 'unsigned short': TypeData(clazz='Primitive', dart_type='int', 830 'unsigned short': TypeData(clazz='Primitive', dart_type='int',
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 # the documentation, the user is made aware that only a limited subset of 864 # the documentation, the user is made aware that only a limited subset of
873 # serializable types are actually permitted. 865 # serializable types are actually permitted.
874 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='Dynamic'), 866 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='Dynamic'),
875 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} 867 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool}
876 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce 868 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce
877 'WebKitFlags': TypeData(clazz='Primitive', dart_type='Object'), 869 'WebKitFlags': TypeData(clazz='Primitive', dart_type='Object'),
878 870
879 'sequence': TypeData(clazz='Primitive', dart_type='List'), 871 'sequence': TypeData(clazz='Primitive', dart_type='List'),
880 'void': TypeData(clazz='Primitive', dart_type='void'), 872 'void': TypeData(clazz='Primitive', dart_type='void'),
881 873
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),
888 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ), 874 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ),
889 'DOMException': TypeData(clazz='Interface', native_type='DOMCoreException'), 875 'DOMException': TypeData(clazz='Interface', native_type='DOMCoreException'),
890 'DOMStringList': TypeData(clazz='Interface', dart_type='List<String>', custo m_to_native=True), 876 'DOMStringList': TypeData(clazz='Interface', dart_type='List<String>', custo m_to_native=True),
891 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') , 877 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') ,
892 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True), 878 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True),
893 'Element': TypeData(clazz='Interface', custom_to_dart=True), 879 'Element': TypeData(clazz='Interface', custom_to_dart=True),
894 'EntryArray': TypeData(clazz='Interface', dart_type='List<Entry>',
895 custom_to_native=True, suppress_public_interface=True),
896 'EntryArraySync': TypeData(clazz='Interface',
897 dart_type='List<EntrySync>', custom_to_native=True,
898 suppress_public_interface=True),
899 'EventListener': TypeData(clazz='Interface', custom_to_native=True), 880 'EventListener': TypeData(clazz='Interface', custom_to_native=True),
900 'EventTarget': TypeData(clazz='Interface', custom_to_native=True), 881 '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),
905 'HTMLElement': TypeData(clazz='Interface', custom_to_dart=True), 882 'HTMLElement': TypeData(clazz='Interface', custom_to_dart=True),
906 'IDBAny': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True), 883 'IDBAny': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True),
907 'IDBKey': TypeData(clazz='Interface', dart_type='Dynamic', custom_to_native= True), 884 '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),
911 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer. 885 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer.
912 native_type='MutationRecordArray', dart_type='List<MutationRecord>'), 886 native_type='MutationRecordArray',
887 dart_type='List<MutationRecord>'),
913 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']), 888 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']),
914 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True), 889 '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),
927 890
928 'SVGAngle': TypeData(clazz='SVGTearOff'), 891 'SVGAngle': TypeData(clazz='SVGTearOff'),
929 'SVGLength': TypeData(clazz='SVGTearOff'), 892 'SVGLength': TypeData(clazz='SVGTearOff'),
930 'SVGLengthList': TypeData(clazz='SVGTearOff'), 893 'SVGLengthList': TypeData(clazz='SVGTearOff'),
931 'SVGMatrix': TypeData(clazz='SVGTearOff'), 894 'SVGMatrix': TypeData(clazz='SVGTearOff'),
932 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'), 895 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'),
933 'SVGNumberList': TypeData(clazz='SVGTearOff'), 896 'SVGNumberList': TypeData(clazz='SVGTearOff'),
934 'SVGPathSegList': TypeData(clazz='SVGTearOff', native_type='SVGPathSegListPr opertyTearOff'), 897 'SVGPathSegList': TypeData(clazz='SVGTearOff', native_type='SVGPathSegListPr opertyTearOff'),
935 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'), 898 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'),
936 'SVGPointList': TypeData(clazz='SVGTearOff'), 899 'SVGPointList': TypeData(clazz='SVGTearOff'),
937 'SVGPreserveAspectRatio': TypeData(clazz='SVGTearOff'), 900 'SVGPreserveAspectRatio': TypeData(clazz='SVGTearOff'),
938 'SVGRect': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Floa tRect>'), 901 'SVGRect': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Floa tRect>'),
939 'SVGStringList': TypeData(clazz='SVGTearOff', native_type='SVGStaticListProp ertyTearOff<SVGStringList>'), 902 'SVGStringList': TypeData(clazz='SVGTearOff', native_type='SVGStaticListProp ertyTearOff<SVGStringList>'),
940 'SVGTransform': TypeData(clazz='SVGTearOff'), 903 'SVGTransform': TypeData(clazz='SVGTearOff'),
941 'SVGTransformList': TypeData(clazz='SVGTearOff', native_type='SVGTransformLi stPropertyTearOff'), 904 'SVGTransformList': TypeData(clazz='SVGTearOff', native_type='SVGTransformLi stPropertyTearOff'),
942 } 905 }
943 906
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
954
955 _svg_supplemental_includes = [ 907 _svg_supplemental_includes = [
956 '"SVGAnimatedPropertyTearOff.h"', 908 '"SVGAnimatedPropertyTearOff.h"',
957 '"SVGAnimatedListPropertyTearOff.h"', 909 '"SVGAnimatedListPropertyTearOff.h"',
958 '"SVGStaticListPropertyTearOff.h"', 910 '"SVGStaticListPropertyTearOff.h"',
959 '"SVGAnimatedListPropertyTearOff.h"', 911 '"SVGAnimatedListPropertyTearOff.h"',
960 '"SVGTransformListPropertyTearOff.h"', 912 '"SVGTransformListPropertyTearOff.h"',
961 '"SVGPathSegListPropertyTearOff.h"', 913 '"SVGPathSegListPropertyTearOff.h"',
962 ] 914 ]
963 915
964 class TypeRegistry(object): 916 class TypeRegistry(object):
(...skipping 22 matching lines...) Expand all
987 if match: 939 if match:
988 if type_name == 'DOMString[]': 940 if type_name == 'DOMString[]':
989 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring')) 941 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring'))
990 item_info = self.TypeInfo(match.group(1) or match.group(2)) 942 item_info = self.TypeInfo(match.group(1) or match.group(2))
991 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) 943 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info)
992 if not type_name in _idl_type_registry: 944 if not type_name in _idl_type_registry:
993 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) 945 return InterfaceIDLTypeInfo(type_name, TypeData('Interface'))
994 type_data = _idl_type_registry.get(type_name) 946 type_data = _idl_type_registry.get(type_name)
995 class_name = '%sIDLTypeInfo' % type_data.clazz 947 class_name = '%sIDLTypeInfo' % type_data.clazz
996 return globals()[class_name](type_name, type_data) 948 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « lib/html/idl/dart/dart.idl ('k') | lib/html/scripts/htmlrenamer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698