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

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

Issue 19820007: Fixes for Blink roll. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minors fixes 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/scripts/fremontcutbuilder.py ('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',
20 #'Crypto',
19 'ElementTimeControl', 21 'ElementTimeControl',
20 'ElementTraversal', 22 'ElementTraversal',
21 'EventListener', 23 'EventListener',
22 'MediaQueryListListener', 24 'MediaQueryListListener',
23 'MutationCallback', 25 'MutationCallback',
26 'ParentNode',
27 #'SubtleCrypto',
Jacob 2013/07/24 16:12:00 remove commented out class names or add comments o
24 'SVGExternalResourcesRequired', 28 'SVGExternalResourcesRequired',
25 'SVGFilterPrimitiveStandardAttributes', 29 'SVGFilterPrimitiveStandardAttributes',
26 'SVGFitToViewBox', 30 'SVGFitToViewBox',
27 'SVGLangSpace', 31 'SVGLangSpace',
28 'SVGLocatable', 32 'SVGLocatable',
29 'SVGTests', 33 'SVGTests',
30 'SVGTransformable', 34 'SVGTransformable',
31 'SVGURIReference', 35 'SVGURIReference',
32 'SVGZoomAndPan', 36 'SVGZoomAndPan',
33 'TimeoutHandler', 37 'TimeoutHandler',
38 'WindowTimers',
39 #'WorkerCrypto',
40 'WorkerPerformance',
34 ]) 41 ])
35 42
36 def IsPureInterface(interface_name): 43 def IsPureInterface(interface_name):
37 return interface_name in _pure_interfaces 44 return interface_name in _pure_interfaces
38 45
39 # 46 #
40 # Classes which have native constructors but which we are suppressing because 47 # Classes which have native constructors but which we are suppressing because
41 # they are not cross-platform. 48 # they are not cross-platform.
42 # 49 #
43 _suppressed_native_constructors = monitored.Set( 50 _suppressed_native_constructors = monitored.Set(
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 'dynamic', 'dynamic') 519 'dynamic', 'dynamic')
513 520
514 dart2js_conversions = monitored.Dict('generator.dart2js_conversions', { 521 dart2js_conversions = monitored.Dict('generator.dart2js_conversions', {
515 'Date get': 522 'Date get':
516 Conversion('convertNativeToDart_DateTime', 'dynamic', 'DateTime'), 523 Conversion('convertNativeToDart_DateTime', 'dynamic', 'DateTime'),
517 'Date set': 524 'Date set':
518 Conversion('convertDartToNative_DateTime', 'DateTime', 'dynamic'), 525 Conversion('convertDartToNative_DateTime', 'DateTime', 'dynamic'),
519 # Wrap non-local Windows. We need to check EventTarget (the base type) 526 # Wrap non-local Windows. We need to check EventTarget (the base type)
520 # as well. Note, there are no functions that take a non-local Window 527 # as well. Note, there are no functions that take a non-local Window
521 # as a parameter / setter. 528 # as a parameter / setter.
522 'DOMWindow get': 529 'Window get':
523 Conversion('_convertNativeToDart_Window', 'dynamic', 'WindowBase'), 530 Conversion('_convertNativeToDart_Window', 'dynamic', 'WindowBase'),
524 'EventTarget get': 531 'EventTarget get':
525 Conversion('_convertNativeToDart_EventTarget', 'dynamic', 532 Conversion('_convertNativeToDart_EventTarget', 'dynamic',
526 'EventTarget'), 533 'EventTarget'),
527 'EventTarget set': 534 'EventTarget set':
528 Conversion('_convertDartToNative_EventTarget', 'EventTarget', 535 Conversion('_convertDartToNative_EventTarget', 'EventTarget',
529 'dynamic'), 536 'dynamic'),
530 537
531 'ImageData get': 538 'ImageData get':
532 Conversion('convertNativeToDart_ImageData', 'dynamic', 'ImageData'), 539 Conversion('convertNativeToDart_ImageData', 'dynamic', 'ImageData'),
533 'ImageData set': 540 'ImageData set':
534 Conversion('convertDartToNative_ImageData', 'ImageData', 'dynamic'), 541 Conversion('convertDartToNative_ImageData', 'ImageData', 'dynamic'),
535 542
536 'Dictionary get': 543 'Dictionary get':
537 Conversion('convertNativeToDart_Dictionary', 'dynamic', 'Map'), 544 Conversion('convertNativeToDart_Dictionary', 'dynamic', 'Map'),
538 'Dictionary set': 545 'Dictionary set':
539 Conversion('convertDartToNative_Dictionary', 'Map', 'dynamic'), 546 Conversion('convertDartToNative_Dictionary', 'Map', 'dynamic'),
540 547
541 'sequence<DOMString> set': 548 'sequence<DOMString> set':
542 Conversion('convertDartToNative_StringArray', 'List<String>', 'List'), 549 Conversion('convertDartToNative_StringArray', 'List<String>', 'List'),
543 550
544 'any set IDBObjectStore.add': _serialize_SSV, 551 'any set IDBObjectStore.add': _serialize_SSV,
545 'any set IDBObjectStore.put': _serialize_SSV, 552 'any set IDBObjectStore.put': _serialize_SSV,
546 'any set IDBCursor.update': _serialize_SSV, 553 'any set IDBCursor.update': _serialize_SSV,
547 554
548 # postMessage 555 # postMessage
549 'any set MessagePort.postMessage': _serialize_SSV, 556 'any set MessagePort.postMessage': _serialize_SSV,
550 'SerializedScriptValue set DOMWindow.postMessage': _serialize_SSV, 557 'SerializedScriptValue set Window.postMessage': _serialize_SSV,
551 558
552 '* get CustomEvent.detail': 559 '* get CustomEvent.detail':
553 Conversion('convertNativeToDart_SerializedScriptValue', 560 Conversion('convertNativeToDart_SerializedScriptValue',
554 'dynamic', 'dynamic'), 561 'dynamic', 'dynamic'),
555 562
556 # receiving message via MessageEvent 563 # receiving message via MessageEvent
557 '* get MessageEvent.data': 564 '* get MessageEvent.data':
558 Conversion('convertNativeToDart_SerializedScriptValue', 565 Conversion('convertNativeToDart_SerializedScriptValue',
559 'dynamic', 'dynamic'), 566 'dynamic', 'dynamic'),
560 567
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 if self.merged_into(): 750 if self.merged_into():
744 return '_%s' % self.idl_type() 751 return '_%s' % self.idl_type()
745 752
746 if not self.has_generated_interface(): 753 if not self.has_generated_interface():
747 implementation_name = '_%s' % implementation_name 754 implementation_name = '_%s' % implementation_name
748 755
749 return implementation_name 756 return implementation_name
750 757
751 def native_type(self): 758 def native_type(self):
752 database = self._type_registry._database 759 database = self._type_registry._database
760
753 if database.HasInterface(self.idl_type()): 761 if database.HasInterface(self.idl_type()):
754 interface = database.GetInterface(self.idl_type()) 762 interface = database.GetInterface(self.idl_type())
755 if 'ImplementedAs' in interface.ext_attrs: 763 if 'ImplementedAs' in interface.ext_attrs:
756 return interface.ext_attrs['ImplementedAs'] 764 return interface.ext_attrs['ImplementedAs']
757 return super(InterfaceIDLTypeInfo, self).native_type() 765 return super(InterfaceIDLTypeInfo, self).native_type()
758 766
759 def has_generated_interface(self): 767 def has_generated_interface(self):
760 return not self._data.suppress_interface 768 return not self._data.suppress_interface
761 769
762 def list_item_type(self): 770 def list_item_type(self):
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 812
805 def vector_to_dart_template_parameter(self): 813 def vector_to_dart_template_parameter(self):
806 raise Exception('sequences of sequences are not supported yet') 814 raise Exception('sequences of sequences are not supported yet')
807 815
808 def to_native_info(self, idl_node, interface_name): 816 def to_native_info(self, idl_node, interface_name):
809 item_native_type = self._item_info.vector_to_dart_template_parameter() 817 item_native_type = self._item_info.vector_to_dart_template_parameter()
810 if isinstance(self._item_info, PrimitiveIDLTypeInfo): 818 if isinstance(self._item_info, PrimitiveIDLTypeInfo):
811 return '%s', 'Vector<%s>' % item_native_type, 'DartUtilities', 'toNativeVe ctor<%s>' % item_native_type 819 return '%s', 'Vector<%s>' % item_native_type, 'DartUtilities', 'toNativeVe ctor<%s>' % item_native_type
812 return '%s', 'Vector< RefPtr<%s> >' % item_native_type, 'DartUtilities', 'to NativeVector< RefPtr<%s> >' % item_native_type 820 return '%s', 'Vector< RefPtr<%s> >' % item_native_type, 'DartUtilities', 'to NativeVector< RefPtr<%s> >' % item_native_type
813 821
822 def parameter_type(self):
823 return self.native_type()
824
814 def pass_native_by_ref(self): return True 825 def pass_native_by_ref(self): return True
815 826
816 def to_dart_conversion(self, value, interface_name=None, attributes=None): 827 def to_dart_conversion(self, value, interface_name=None, attributes=None):
817 if isinstance(self._item_info, PrimitiveIDLTypeInfo): 828 if isinstance(self._item_info, PrimitiveIDLTypeInfo):
818 return 'DartDOMWrapper::vectorToDart(%s)' % value 829 return 'DartDOMWrapper::vectorToDart(%s)' % value
819 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.bindings_cl ass(), value) 830 return 'DartDOMWrapper::vectorToDart<%s>(%s)' % (self._item_info.bindings_cl ass(), value)
820 831
821 def conversion_includes(self): 832 def conversion_includes(self):
822 return self._item_info.conversion_includes() 833 return self._item_info.conversion_includes()
823 834
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 'PositionOptions': TypeData(clazz='Primitive', dart_type='Object'), 1032 'PositionOptions': TypeData(clazz='Primitive', dart_type='Object'),
1022 # TODO(sra): Come up with some meaningful name so that where this appears in 1033 # TODO(sra): Come up with some meaningful name so that where this appears in
1023 # the documentation, the user is made aware that only a limited subset of 1034 # the documentation, the user is made aware that only a limited subset of
1024 # serializable types are actually permitted. 1035 # serializable types are actually permitted.
1025 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='dynamic'), 1036 'SerializedScriptValue': TypeData(clazz='Primitive', dart_type='dynamic'),
1026 'sequence': TypeData(clazz='Primitive', dart_type='List'), 1037 'sequence': TypeData(clazz='Primitive', dart_type='List'),
1027 'void': TypeData(clazz='Primitive', dart_type='void'), 1038 'void': TypeData(clazz='Primitive', dart_type='void'),
1028 1039
1029 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ), 1040 'CSSRule': TypeData(clazz='Interface', conversion_includes=['CSSImportRule'] ),
1030 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') , 1041 'DOMStringMap': TypeData(clazz='Interface', dart_type='Map<String, String>') ,
1031 'DOMWindow': TypeData(clazz='Interface', custom_to_dart=True), 1042 'Window': TypeData(clazz='Interface', custom_to_dart=True),
1032 'Element': TypeData(clazz='Interface', merged_interface='HTMLElement', 1043 'Element': TypeData(clazz='Interface', merged_interface='HTMLElement',
1033 custom_to_dart=True), 1044 custom_to_dart=True),
1034 'EventListener': TypeData(clazz='Interface', custom_to_native=True), 1045 'EventListener': TypeData(clazz='Interface', custom_to_native=True),
1035 'EventTarget': TypeData(clazz='Interface', custom_to_native=True), 1046 'EventTarget': TypeData(clazz='Interface', custom_to_native=True),
1036 'HTMLElement': TypeData(clazz='Interface', merged_into='Element', 1047 'HTMLElement': TypeData(clazz='Interface', merged_into='Element',
1037 custom_to_dart=True), 1048 custom_to_dart=True),
1038 'IDBAny': TypeData(clazz='Interface', dart_type='dynamic', custom_to_native= True), 1049 'IDBAny': TypeData(clazz='Interface', dart_type='dynamic', custom_to_native= True),
1039 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer. 1050 'MutationRecordArray': TypeData(clazz='Interface', # C++ pass by pointer.
1040 native_type='MutationRecordArray', dart_type='List<MutationRecord>'), 1051 native_type='MutationRecordArray', dart_type='List<MutationRecord>'),
1041 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']), 1052 'StyleSheet': TypeData(clazz='Interface', conversion_includes=['CSSStyleShee t']),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 if not type_name in self._cache: 1144 if not type_name in self._cache:
1134 self._cache[type_name] = self._TypeInfo(type_name) 1145 self._cache[type_name] = self._TypeInfo(type_name)
1135 return self._cache[type_name] 1146 return self._cache[type_name]
1136 1147
1137 def DartType(self, type_name): 1148 def DartType(self, type_name):
1138 return self.TypeInfo(type_name).dart_type() 1149 return self.TypeInfo(type_name).dart_type()
1139 1150
1140 def _TypeInfo(self, type_name): 1151 def _TypeInfo(self, type_name):
1141 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name) 1152 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name)
1142 if match: 1153 if match:
1154 type_data = TypeData('Sequence')
1143 if type_name == 'DOMString[]': 1155 if type_name == 'DOMString[]':
1144 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring')) 1156 return DOMStringArrayTypeInfo(type_data, self.TypeInfo('DOMString'))
1145 item_info = self.TypeInfo(match.group(1) or match.group(2)) 1157 item_info = self.TypeInfo(match.group(1) or match.group(2))
1146 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) 1158 # TODO(vsm): Generalize this code.
1159 if 'SourceInfo' in type_name:
1160 type_data.native_type = 'Vector<RefPtr<SourceInfo> >'
1161 return SequenceIDLTypeInfo(type_name, type_data, item_info)
1147 1162
1148 if not type_name in _idl_type_registry: 1163 if not type_name in _idl_type_registry:
1149 if self._database.HasEnum(type_name): 1164 if self._database.HasEnum(type_name):
1150 return PrimitiveIDLTypeInfo( 1165 return PrimitiveIDLTypeInfo(
1151 type_name, 1166 type_name,
1152 TypeData(clazz='Primitive', dart_type='String', native_type='String' )) 1167 TypeData(clazz='Primitive', dart_type='String', native_type='String' ))
1153 1168
1154 interface = self._database.GetInterface(type_name) 1169 interface = self._database.GetInterface(type_name)
1155 if 'Callback' in interface.ext_attrs: 1170 if 'Callback' in interface.ext_attrs:
1156 return CallbackIDLTypeInfo(type_name, TypeData('Callback', 1171 return CallbackIDLTypeInfo(type_name, TypeData('Callback',
(...skipping 28 matching lines...) Expand all
1185 type_name, type_data, dart_interface_name, self) 1200 type_name, type_data, dart_interface_name, self)
1186 1201
1187 if type_data.clazz == 'BasicTypedList': 1202 if type_data.clazz == 'BasicTypedList':
1188 dart_interface_name = self._renamer.RenameInterface( 1203 dart_interface_name = self._renamer.RenameInterface(
1189 self._database.GetInterface(type_name)) 1204 self._database.GetInterface(type_name))
1190 return BasicTypedListIDLTypeInfo( 1205 return BasicTypedListIDLTypeInfo(
1191 type_name, type_data, dart_interface_name, self) 1206 type_name, type_data, dart_interface_name, self)
1192 1207
1193 class_name = '%sIDLTypeInfo' % type_data.clazz 1208 class_name = '%sIDLTypeInfo' % type_data.clazz
1194 return globals()[class_name](type_name, type_data) 1209 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « tools/dom/scripts/fremontcutbuilder.py ('k') | tools/dom/scripts/htmldartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698