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

Side by Side Diff: tools/dom/scripts/generator.py

Issue 23163010: rollback problem blink merge cl (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 | « tools/dom/idl/dart/dart.idl ('k') | tools/dom/scripts/htmldartgenerator.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 json 10 import json
11 import monitored 11 import monitored
12 import os 12 import os
13 import re 13 import re
14 from htmlrenamer import html_interface_renames, typed_array_renames 14 from htmlrenamer import html_interface_renames, typed_array_renames
15 15
16 _pure_interfaces = monitored.Set('generator._pure_interfaces', [ 16 _pure_interfaces = monitored.Set('generator._pure_interfaces', [
17 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. 17 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>.
18 'DOMStringMap', 18 'DOMStringMap',
19 'ChildNode', 19 'ChildNode',
20 'EventListener', 20 'EventListener',
21 'EventHandler',
22 'MediaQueryListListener', 21 'MediaQueryListListener',
23 'MutationCallback', 22 'MutationCallback',
24 'ParentNode', 23 'ParentNode',
25 'SVGExternalResourcesRequired', 24 'SVGExternalResourcesRequired',
26 'SVGFilterPrimitiveStandardAttributes', 25 'SVGFilterPrimitiveStandardAttributes',
27 'SVGFitToViewBox', 26 'SVGFitToViewBox',
28 'SVGTests', 27 'SVGTests',
29 'SVGURIReference', 28 'SVGURIReference',
30 'SVGZoomAndPan', 29 'SVGZoomAndPan',
31 'TimeoutHandler', 30 'TimeoutHandler',
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 776
778 def merged_into(self): 777 def merged_into(self):
779 return self._data.merged_into 778 return self._data.merged_into
780 779
781 780
782 class CallbackIDLTypeInfo(IDLTypeInfo): 781 class CallbackIDLTypeInfo(IDLTypeInfo):
783 def __init__(self, idl_type, data): 782 def __init__(self, idl_type, data):
784 super(CallbackIDLTypeInfo, self).__init__(idl_type, data) 783 super(CallbackIDLTypeInfo, self).__init__(idl_type, data)
785 784
786 785
787 def array_type(data_type):
788 matched = re.match(r'([\w\d_\s]+)\[\]', data_type)
789 if not matched:
790 return None
791 return matched.group(1)
792
793 class SequenceIDLTypeInfo(IDLTypeInfo): 786 class SequenceIDLTypeInfo(IDLTypeInfo):
794 def __init__(self, idl_type, data, item_info): 787 def __init__(self, idl_type, data, item_info):
795 super(SequenceIDLTypeInfo, self).__init__(idl_type, data) 788 super(SequenceIDLTypeInfo, self).__init__(idl_type, data)
796 self._item_info = item_info 789 self._item_info = item_info
797 790
798 def dart_type(self): 791 def dart_type(self):
799 return 'List<%s>' % self._item_info.dart_type() 792 return 'List<%s>' % self._item_info.dart_type()
800 793
801 def interface_name(self): 794 def interface_name(self):
802 return self.dart_type() 795 return self.dart_type()
803 796
804 def implementation_name(self): 797 def implementation_name(self):
805 return self.dart_type() 798 return self.dart_type()
806 799
807 def vector_to_dart_template_parameter(self): 800 def vector_to_dart_template_parameter(self):
808 raise Exception('sequences of sequences are not supported yet') 801 raise Exception('sequences of sequences are not supported yet')
809 802
810 def to_native_info(self, idl_node, interface_name): 803 def to_native_info(self, idl_node, interface_name):
811 item_native_type = self._item_info.vector_to_dart_template_parameter() 804 item_native_type = self._item_info.vector_to_dart_template_parameter()
812 if isinstance(self._item_info, PrimitiveIDLTypeInfo): 805 if isinstance(self._item_info, PrimitiveIDLTypeInfo):
813 return '%s', 'Vector<%s>' % item_native_type, 'DartUtilities', 'toNativeVe ctor<%s>' % item_native_type 806 return '%s', 'Vector<%s>' % item_native_type, 'DartUtilities', 'toNativeVe ctor<%s>' % item_native_type
814 return '%s', 'Vector< RefPtr<%s> >' % item_native_type, 'DartUtilities', 'to NativeVector< RefPtr<%s> >' % item_native_type 807 return '%s', 'Vector< RefPtr<%s> >' % item_native_type, 'DartUtilities', 'to NativeVector< RefPtr<%s> >' % item_native_type
815 808
816 def parameter_type(self): 809 def parameter_type(self):
817 native_type = self.native_type() 810 return self.native_type()
818 if array_type(native_type):
819 return 'const Vector<RefPtr<%s> > &' % array_type(native_type)
820
821 return native_type
822 811
823 def pass_native_by_ref(self): return True 812 def pass_native_by_ref(self): return True
824 813
825 def to_dart_conversion(self, value, interface_name=None, attributes=None): 814 def to_dart_conversion(self, value, interface_name=None, attributes=None):
826 if isinstance(self._item_info, PrimitiveIDLTypeInfo): 815 if isinstance(self._item_info, PrimitiveIDLTypeInfo):
827 return 'DartDOMWrapper::vectorToDart(%s)' % value 816 return 'DartDOMWrapper::vectorToDart(%s)' % value
828 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.bindings_cl ass(), value) 817 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.bindings_cl ass(), value)
829 818
830 def conversion_includes(self): 819 def conversion_includes(self):
831 return self._item_info.conversion_includes() 820 return self._item_info.conversion_includes()
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='dynamic'), 1023 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='dynamic'),
1035 'sequence': TypeData(clazz='Primitive', dart_type='List'), 1024 'sequence': TypeData(clazz='Primitive', dart_type='List'),
1036 'void': TypeData(clazz='Primitive', dart_type='void'), 1025 'void': TypeData(clazz='Primitive', dart_type='void'),
1037 1026
1038 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ), 1027 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ),
1039 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') , 1028 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') ,
1040 'Window': TypeData(clazz='Interface', custom_to_dart=True), 1029 'Window': TypeData(clazz='Interface', custom_to_dart=True),
1041 'Element': TypeData(clazz='Interface', merged_interface='HTMLElement', 1030 'Element': TypeData(clazz='Interface', merged_interface='HTMLElement',
1042 custom_to_dart=True), 1031 custom_to_dart=True),
1043 'EventListener': TypeData(clazz='Interface', custom_to_native=True), 1032 'EventListener': TypeData(clazz='Interface', custom_to_native=True),
1044 'EventHandler': TypeData(clazz='Interface', custom_to_native=True),
1045 'EventTarget': TypeData(clazz='Interface', custom_to_native=True), 1033 'EventTarget': TypeData(clazz='Interface', custom_to_native=True),
1046 'HTMLElement': TypeData(clazz='Interface', merged_into='Element', 1034 'HTMLElement': TypeData(clazz='Interface', merged_into='Element',
1047 custom_to_dart=True), 1035 custom_to_dart=True),
1048 'IDBAny': TypeData(clazz='Interface', dart_type='dynamic', custom_to_native= True), 1036 'IDBAny': TypeData(clazz='Interface', dart_type='dynamic', custom_to_native= True),
1049 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer. 1037 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer.
1050 native_type='MutationRecordArray', dart_type='List<MutationRecord>'), 1038 native_type='MutationRecordArray', dart_type='List<MutationRecord>'),
1051 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']), 1039 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']),
1052 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True), 1040 'SVGElement': TypeData(clazz='Interface', custom_to_dart=True),
1053 1041
1054 'ClientRectList': TypeData(clazz='Interface', 1042 'ClientRectList': TypeData(clazz='Interface',
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 def DartType(self, type_name): 1135 def DartType(self, type_name):
1148 return self.TypeInfo(type_name).dart_type() 1136 return self.TypeInfo(type_name).dart_type()
1149 1137
1150 def _TypeInfo(self, type_name): 1138 def _TypeInfo(self, type_name):
1151 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name) 1139 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name)
1152 if match: 1140 if match:
1153 type_data = TypeData('Sequence') 1141 type_data = TypeData('Sequence')
1154 item_info = self.TypeInfo(match.group(1) or match.group(2)) 1142 item_info = self.TypeInfo(match.group(1) or match.group(2))
1155 # TODO(vsm): Generalize this code. 1143 # TODO(vsm): Generalize this code.
1156 if 'SourceInfo' in type_name: 1144 if 'SourceInfo' in type_name:
1157 type_data.native_type = 'const Vector<RefPtr<SourceInfo> >& ' 1145 type_data.native_type = 'Vector<RefPtr<SourceInfo> >'
1158 return SequenceIDLTypeInfo(type_name, type_data, item_info) 1146 return SequenceIDLTypeInfo(type_name, type_data, item_info)
1159 1147
1160 if not type_name in _idl_type_registry: 1148 if not type_name in _idl_type_registry:
1161 if self._database.HasEnum(type_name): 1149 if self._database.HasEnum(type_name):
1162 return PrimitiveIDLTypeInfo( 1150 return PrimitiveIDLTypeInfo(
1163 type_name, 1151 type_name,
1164 TypeData(clazz='Primitive', dart_type='String', native_type='String' )) 1152 TypeData(clazz='Primitive', dart_type='String', native_type='String' ))
1165 1153
1166 interface = self._database.GetInterface(type_name) 1154 interface = self._database.GetInterface(type_name)
1167 if 'Callback' in interface.ext_attrs: 1155 if 'Callback' in interface.ext_attrs:
(...skipping 16 matching lines...) Expand all
1184 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name, 1172 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name,
1185 self) 1173 self)
1186 1174
1187 if type_data.clazz == 'SVGTearOff': 1175 if type_data.clazz == 'SVGTearOff':
1188 dart_interface_name = self._renamer.RenameInterface( 1176 dart_interface_name = self._renamer.RenameInterface(
1189 self._database.GetInterface(type_name)) 1177 self._database.GetInterface(type_name))
1190 return SVGTearOffIDLTypeInfo( 1178 return SVGTearOffIDLTypeInfo(
1191 type_name, type_data, dart_interface_name, self) 1179 type_name, type_data, dart_interface_name, self)
1192 1180
1193 if type_data.clazz == 'TypedList': 1181 if type_data.clazz == 'TypedList':
1194 dart_interface_name = self._renamer.RenameInterfaceId(type_name) 1182 dart_interface_name = self._renamer.RenameInterface(
1183 self._database.GetInterface(type_name))
1195 return TypedListIDLTypeInfo( 1184 return TypedListIDLTypeInfo(
1196 type_name, type_data, dart_interface_name, self) 1185 type_name, type_data, dart_interface_name, self)
1197 1186
1198 if type_data.clazz == 'BasicTypedList': 1187 if type_data.clazz == 'BasicTypedList':
1199 if type_name == 'ArrayBuffer': 1188 if type_name == 'ArrayBuffer':
1200 dart_interface_name = 'ByteBuffer' 1189 dart_interface_name = 'ByteBuffer'
1201 else: 1190 else:
1202 dart_interface_name = self._renamer.RenameInterfaceId(type_name) 1191 dart_interface_name = self._renamer.RenameInterface(
1192 self._database.GetInterface(type_name))
1203 return BasicTypedListIDLTypeInfo( 1193 return BasicTypedListIDLTypeInfo(
1204 type_name, type_data, dart_interface_name, self) 1194 type_name, type_data, dart_interface_name, self)
1205 1195
1206 class_name = '%sIDLTypeInfo' % type_data.clazz 1196 class_name = '%sIDLTypeInfo' % type_data.clazz
1207 return globals()[class_name](type_name, type_data) 1197 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « tools/dom/idl/dart/dart.idl ('k') | tools/dom/scripts/htmldartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698