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

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

Issue 11227024: Cleanup list-like interfaces generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 # console). 65 # console).
66 'Console': "=(typeof console == 'undefined' ? {} : console)", 66 'Console': "=(typeof console == 'undefined' ? {} : console)",
67 67
68 # DOMWindow aliased with global scope. 68 # DOMWindow aliased with global scope.
69 'DOMWindow': '@*DOMWindow', 69 'DOMWindow': '@*DOMWindow',
70 } 70 }
71 71
72 def IsRegisteredType(type_name): 72 def IsRegisteredType(type_name):
73 return type_name in _idl_type_registry 73 return type_name in _idl_type_registry
74 74
75 def ListImplementationInfo(interface, database):
76 """Returns a tuple (elment_type, requires_indexer).
77 If interface do not have to implement List, element_type is None.
78 Otherwise element_type is list element type and requires_indexer
79 is true iff this interface implementation must have indexer and
80 false otherwise. False means that interface implementation
81 inherits indexer and may just reuse it."""
82 element_type = MaybeListElementType(interface)
83 if element_type:
84 return (element_type, True)
85
86 for parent in interface.parents:
87 if database.HasInterface(parent.type.id):
88 parent_interface = database.GetInterface(parent.type.id)
89 (element_type, _) = ListImplementationInfo(parent_interface, database)
90 if element_type:
91 return (element_type, False)
92
93 return (None, None)
94
95
96 def MaybeListElementType(interface):
97 """Returns the List element type T, or None in interface does not implement
98 List<T>.
99 """
100 for parent in interface.parents:
101 match = re.match(r'sequence<(\w*)>$', parent.type.id)
102 if match:
103 return match.group(1)
104 return None
105
106 def MaybeTypedArrayElementType(interface):
107 """Returns the typed array element type, or None in interface is not a
108 TypedArray.
109 """
110 # Typed arrays implement ArrayBufferView and List<T>.
111 for parent in interface.parents:
112 if parent.type.id == 'ArrayBufferView':
113 return MaybeListElementType(interface)
114 return None
115
116 def MaybeTypedArrayElementTypeInHierarchy(interface, database):
117 """Returns the typed array element type, or None in interface is not a
118 TypedArray. Checks the whole parent hierarchy.
119 """
120 element_type = MaybeTypedArrayElementType(interface)
121 if element_type:
122 return element_type
123 for parent in interface.parents:
124 if database.HasInterface(parent.type.id):
125 parent_interface = database.GetInterface(parent.type.id)
126 element_type = MaybeTypedArrayElementType(parent_interface)
127 if element_type:
128 return element_type
129
130 return None
131
132 def MakeNativeSpec(javascript_binding_name): 75 def MakeNativeSpec(javascript_binding_name):
133 if javascript_binding_name in _dart2js_dom_custom_native_specs: 76 if javascript_binding_name in _dart2js_dom_custom_native_specs:
134 return _dart2js_dom_custom_native_specs[javascript_binding_name] 77 return _dart2js_dom_custom_native_specs[javascript_binding_name]
135 else: 78 else:
136 # Make the class 'hidden' so it is dynamically patched at runtime. This 79 # Make the class 'hidden' so it is dynamically patched at runtime. This
137 # is useful for browser compat. 80 # is useful for browser compat.
138 return '*' + javascript_binding_name 81 return '*' + javascript_binding_name
139 82
140 83
141 def MatchSourceFilter(thing): 84 def MatchSourceFilter(thing):
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 548
606 def implementation_name(self): 549 def implementation_name(self):
607 raise NotImplementedError() 550 raise NotImplementedError()
608 551
609 def has_generated_interface(self): 552 def has_generated_interface(self):
610 raise NotImplementedError() 553 raise NotImplementedError()
611 554
612 def list_item_type(self): 555 def list_item_type(self):
613 raise NotImplementedError() 556 raise NotImplementedError()
614 557
558 def is_typed_array(self):
559 raise NotImplementedError()
560
615 def merged_interface(self): 561 def merged_interface(self):
616 return None 562 return None
617 563
618 def merged_into(self): 564 def merged_into(self):
619 return None 565 return None
620 566
621 def native_type(self): 567 def native_type(self):
622 return self._data.native_type or self._idl_type 568 return self._data.native_type or self._idl_type
623 569
624 def bindings_class(self): 570 def bindings_class(self):
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 if self.merged_into(): 685 if self.merged_into():
740 implementation_name = '%s_Merged' % implementation_name 686 implementation_name = '%s_Merged' % implementation_name
741 return implementation_name 687 return implementation_name
742 688
743 def has_generated_interface(self): 689 def has_generated_interface(self):
744 return not self._data.suppress_interface 690 return not self._data.suppress_interface
745 691
746 def list_item_type(self): 692 def list_item_type(self):
747 return self._data.item_type 693 return self._data.item_type
748 694
695 def is_typed_array(self):
696 return self._data.is_typed_array
697
749 def merged_interface(self): 698 def merged_interface(self):
750 # All constants, attributes, and operations of merged interface should be 699 # All constants, attributes, and operations of merged interface should be
751 # added to this interface. Merged idl interface does not have corresponding 700 # added to this interface. Merged idl interface does not have corresponding
752 # Dart generated interface, and all references to merged idl interface 701 # Dart generated interface, and all references to merged idl interface
753 # (e.g. parameter types, return types, parent interfaces) should be replaced 702 # (e.g. parameter types, return types, parent interfaces) should be replaced
754 # with this interface. There are two important restrictions: 703 # with this interface. There are two important restrictions:
755 # 1) Merged and target interfaces shouldn't have common members, otherwise 704 # 1) Merged and target interfaces shouldn't have common members, otherwise
756 # there would be duplicated declarations in generated Dart code. 705 # there would be duplicated declarations in generated Dart code.
757 # 2) Merged interface should be direct child of target interface, so the 706 # 2) Merged interface should be direct child of target interface, so the
758 # children of merged interface are not affected by the merge. 707 # children of merged interface are not affected by the merge.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 845
897 846
898 class TypeData(object): 847 class TypeData(object):
899 def __init__(self, clazz, dart_type=None, native_type=None, 848 def __init__(self, clazz, dart_type=None, native_type=None,
900 merged_interface=None, merged_into=None, 849 merged_interface=None, merged_into=None,
901 custom_to_dart=None, custom_to_native=None, 850 custom_to_dart=None, custom_to_native=None,
902 conversion_includes=None, 851 conversion_includes=None,
903 webcore_getter_name='getAttribute', 852 webcore_getter_name='getAttribute',
904 webcore_setter_name='setAttribute', 853 webcore_setter_name='setAttribute',
905 requires_v8_scope=False, 854 requires_v8_scope=False,
906 item_type=None, suppress_interface=False): 855 item_type=None, suppress_interface=False, is_typed_array=False):
907 self.clazz = clazz 856 self.clazz = clazz
908 self.dart_type = dart_type 857 self.dart_type = dart_type
909 self.native_type = native_type 858 self.native_type = native_type
910 self.merged_interface = merged_interface 859 self.merged_interface = merged_interface
911 self.merged_into = merged_into 860 self.merged_into = merged_into
912 self.custom_to_dart = custom_to_dart 861 self.custom_to_dart = custom_to_dart
913 self.custom_to_native = custom_to_native 862 self.custom_to_native = custom_to_native
914 self.conversion_includes = conversion_includes 863 self.conversion_includes = conversion_includes
915 self.webcore_getter_name = webcore_getter_name 864 self.webcore_getter_name = webcore_getter_name
916 self.webcore_setter_name = webcore_setter_name 865 self.webcore_setter_name = webcore_setter_name
917 self.requires_v8_scope = requires_v8_scope 866 self.requires_v8_scope = requires_v8_scope
918 self.item_type = item_type 867 self.item_type = item_type
919 self.suppress_interface = suppress_interface 868 self.suppress_interface = suppress_interface
869 self.is_typed_array = is_typed_array
870
871
872 def TypedArrayTypeData(item_type):
873 return TypeData(clazz='Interface', item_type=item_type, is_typed_array=True)
920 874
921 875
922 _idl_type_registry = { 876 _idl_type_registry = {
923 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', 877 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool',
924 webcore_getter_name='hasAttribute', 878 webcore_getter_name='hasAttribute',
925 webcore_setter_name='setBooleanAttribute'), 879 webcore_setter_name='setBooleanAttribute'),
926 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 880 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
927 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 881 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
928 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 882 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
929 'unsigned short': TypeData(clazz='Primitive', dart_type='int', 883 'unsigned short': TypeData(clazz='Primitive', dart_type='int',
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 item_type='SpeechRecognitionResult', suppress_interface=True), 983 item_type='SpeechRecognitionResult', suppress_interface=True),
1030 'SQLResultSetRowList': TypeData(clazz='Interface', item_type='Dictionary'), 984 'SQLResultSetRowList': TypeData(clazz='Interface', item_type='Dictionary'),
1031 'StyleSheetList': TypeData(clazz='Interface', 985 'StyleSheetList': TypeData(clazz='Interface',
1032 item_type='StyleSheet', suppress_interface=True), 986 item_type='StyleSheet', suppress_interface=True),
1033 'TextTrackCueList': TypeData(clazz='Interface', item_type='TextTrackCue'), 987 'TextTrackCueList': TypeData(clazz='Interface', item_type='TextTrackCue'),
1034 'TextTrackList': TypeData(clazz='Interface', item_type='TextTrack'), 988 'TextTrackList': TypeData(clazz='Interface', item_type='TextTrack'),
1035 'TouchList': TypeData(clazz='Interface', item_type='Touch'), 989 'TouchList': TypeData(clazz='Interface', item_type='Touch'),
1036 'WebKitAnimationList': TypeData(clazz='Interface', 990 'WebKitAnimationList': TypeData(clazz='Interface',
1037 item_type='WebKitAnimation', suppress_interface=True), 991 item_type='WebKitAnimation', suppress_interface=True),
1038 992
1039 'Float32Array': TypeData(clazz='Interface', item_type='double'), 993 'Float32Array': TypedArrayTypeData('double'),
1040 'Float64Array': TypeData(clazz='Interface', item_type='double'), 994 'Float64Array': TypedArrayTypeData('double'),
1041 'Int8Array': TypeData(clazz='Interface', item_type='int'), 995 'Int8Array': TypedArrayTypeData('int'),
1042 'Int16Array': TypeData(clazz='Interface', item_type='int'), 996 'Int16Array': TypedArrayTypeData('int'),
1043 'Int32Array': TypeData(clazz='Interface', item_type='int'), 997 'Int32Array': TypedArrayTypeData('int'),
1044 'Uint8Array': TypeData(clazz='Interface', item_type='int'), 998 'Uint8Array': TypedArrayTypeData('int'),
1045 'Uint16Array': TypeData(clazz='Interface', item_type='int'), 999 'Uint16Array': TypedArrayTypeData('int'),
1046 'Uint32Array': TypeData(clazz='Interface', item_type='int'), 1000 'Uint32Array': TypedArrayTypeData('int'),
1047 1001
1048 'SVGAngle': TypeData(clazz='SVGTearOff'), 1002 'SVGAngle': TypeData(clazz='SVGTearOff'),
1049 'SVGLength': TypeData(clazz='SVGTearOff'), 1003 'SVGLength': TypeData(clazz='SVGTearOff'),
1050 'SVGLengthList': TypeData(clazz='SVGTearOff', item_type='SVGLength'), 1004 'SVGLengthList': TypeData(clazz='SVGTearOff', item_type='SVGLength'),
1051 'SVGMatrix': TypeData(clazz='SVGTearOff'), 1005 'SVGMatrix': TypeData(clazz='SVGTearOff'),
1052 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'), 1006 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'),
1053 'SVGNumberList': TypeData(clazz='SVGTearOff', item_type='SVGNumber'), 1007 'SVGNumberList': TypeData(clazz='SVGTearOff', item_type='SVGNumber'),
1054 'SVGPathSegList': TypeData(clazz='SVGTearOff', item_type='SVGPathSeg', 1008 'SVGPathSegList': TypeData(clazz='SVGTearOff', item_type='SVGPathSeg',
1055 native_type='SVGPathSegListPropertyTearOff'), 1009 native_type='SVGPathSegListPropertyTearOff'),
1056 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'), 1010 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 else: 1068 else:
1115 dart_interface_name = type_name 1069 dart_interface_name = type_name
1116 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name, 1070 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name,
1117 self) 1071 self)
1118 1072
1119 if type_data.clazz == 'SVGTearOff': 1073 if type_data.clazz == 'SVGTearOff':
1120 return SVGTearOffIDLTypeInfo(type_name, type_data, self) 1074 return SVGTearOffIDLTypeInfo(type_name, type_data, self)
1121 1075
1122 class_name = '%sIDLTypeInfo' % type_data.clazz 1076 class_name = '%sIDLTypeInfo' % type_data.clazz
1123 return globals()[class_name](type_name, type_data) 1077 return globals()[class_name](type_name, type_data)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698