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

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

Issue 14367047: Some more cleanups. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | « no previous file | 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
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 # interface and member name, and by IDL return or field type name. Both are 538 # interface and member name, and by IDL return or field type name. Both are
539 # used to assemble the annotations: 539 # used to assemble the annotations:
540 # 540 #
541 # INTERFACE.MEMBER: annotations for member. 541 # INTERFACE.MEMBER: annotations for member.
542 # +TYPE: add annotations only if there are member annotations. 542 # +TYPE: add annotations only if there are member annotations.
543 # -TYPE: add annotations only if there are no member annotations. 543 # -TYPE: add annotations only if there are no member annotations.
544 # TYPE: add regardless of member annotations. 544 # TYPE: add regardless of member annotations.
545 545
546 dart2js_annotations = monitored.Dict('generator.dart2js_annotations', { 546 dart2js_annotations = monitored.Dict('generator.dart2js_annotations', {
547 547
548 'ArrayBuffer': [
549 "@Creates('ByteBuffer')",
550 "@Returns('ByteBuffer|Null')",
551 ],
552
553 'ArrayBufferView': [ 548 'ArrayBufferView': [
554 "@Creates('TypedData')", 549 "@Creates('TypedData')",
555 "@Returns('TypedData|Null')", 550 "@Returns('TypedData|Null')",
556 ], 551 ],
557 552
558 'CanvasRenderingContext2D.createImageData': [ 553 'CanvasRenderingContext2D.createImageData': [
559 "@Creates('ImageData|=Object')", 554 "@Creates('ImageData|=Object')",
560 ], 555 ],
561 556
562 'CanvasRenderingContext2D.getImageData': [ 557 'CanvasRenderingContext2D.getImageData': [
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 "@SupportedBrowser(SupportedBrowser.CHROME)", 753 "@SupportedBrowser(SupportedBrowser.CHROME)",
759 "@SupportedBrowser(SupportedBrowser.SAFARI)", 754 "@SupportedBrowser(SupportedBrowser.SAFARI)",
760 "@Experimental", 755 "@Experimental",
761 ] 756 ]
762 757
763 # Annotations to be placed on generated members. 758 # Annotations to be placed on generated members.
764 # The table is indexed as: 759 # The table is indexed as:
765 # INTERFACE: annotations to be added to the interface declaration 760 # INTERFACE: annotations to be added to the interface declaration
766 # INTERFACE.MEMBER: annotation to be added to the member declaration 761 # INTERFACE.MEMBER: annotation to be added to the member declaration
767 dart_annotations = monitored.Dict('generator.dart_annotations', { 762 dart_annotations = monitored.Dict('generator.dart_annotations', {
768 'ArrayBuffer': _all_but_ie9_annotations,
769 'ArrayBufferView': _all_but_ie9_annotations,
770 'CSSHostRule': _shadow_dom_annotations, 763 'CSSHostRule': _shadow_dom_annotations,
771 'Crypto': _webkit_experimental_annotations, 764 'Crypto': _webkit_experimental_annotations,
772 'Database': _web_sql_annotations, 765 'Database': _web_sql_annotations,
773 'DatabaseSync': _web_sql_annotations, 766 'DatabaseSync': _web_sql_annotations,
774 'DOMApplicationCache': [ 767 'DOMApplicationCache': [
775 "@SupportedBrowser(SupportedBrowser.CHROME)", 768 "@SupportedBrowser(SupportedBrowser.CHROME)",
776 "@SupportedBrowser(SupportedBrowser.FIREFOX)", 769 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
777 "@SupportedBrowser(SupportedBrowser.IE, '10')", 770 "@SupportedBrowser(SupportedBrowser.IE, '10')",
778 "@SupportedBrowser(SupportedBrowser.OPERA)", 771 "@SupportedBrowser(SupportedBrowser.OPERA)",
779 "@SupportedBrowser(SupportedBrowser.SAFARI)", 772 "@SupportedBrowser(SupportedBrowser.SAFARI)",
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 1015
1023 def implementation_name(self): 1016 def implementation_name(self):
1024 raise NotImplementedError() 1017 raise NotImplementedError()
1025 1018
1026 def has_generated_interface(self): 1019 def has_generated_interface(self):
1027 raise NotImplementedError() 1020 raise NotImplementedError()
1028 1021
1029 def list_item_type(self): 1022 def list_item_type(self):
1030 raise NotImplementedError() 1023 raise NotImplementedError()
1031 1024
1032 def is_typed_array(self):
1033 raise NotImplementedError()
1034
1035 def merged_interface(self): 1025 def merged_interface(self):
1036 return None 1026 return None
1037 1027
1038 def merged_into(self): 1028 def merged_into(self):
1039 return None 1029 return None
1040 1030
1041 def native_type(self): 1031 def native_type(self):
1042 return self._data.native_type or self._idl_type 1032 return self._data.native_type or self._idl_type
1043 1033
1044 def bindings_class(self): 1034 def bindings_class(self):
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 implementation_name = '_%s' % implementation_name 1141 implementation_name = '_%s' % implementation_name
1152 1142
1153 return implementation_name 1143 return implementation_name
1154 1144
1155 def has_generated_interface(self): 1145 def has_generated_interface(self):
1156 return not self._data.suppress_interface 1146 return not self._data.suppress_interface
1157 1147
1158 def list_item_type(self): 1148 def list_item_type(self):
1159 return self._data.item_type 1149 return self._data.item_type
1160 1150
1161 def is_typed_array(self):
1162 return self._data.is_typed_array
1163
1164 def merged_interface(self): 1151 def merged_interface(self):
1165 # All constants, attributes, and operations of merged interface should be 1152 # All constants, attributes, and operations of merged interface should be
1166 # added to this interface. Merged idl interface does not have corresponding 1153 # added to this interface. Merged idl interface does not have corresponding
1167 # Dart generated interface, and all references to merged idl interface 1154 # Dart generated interface, and all references to merged idl interface
1168 # (e.g. parameter types, return types, parent interfaces) should be replaced 1155 # (e.g. parameter types, return types, parent interfaces) should be replaced
1169 # with this interface. There are two important restrictions: 1156 # with this interface. There are two important restrictions:
1170 # 1) Merged and target interfaces shouldn't have common members, otherwise 1157 # 1) Merged and target interfaces shouldn't have common members, otherwise
1171 # there would be duplicated declarations in generated Dart code. 1158 # there would be duplicated declarations in generated Dart code.
1172 # 2) Merged interface should be direct child of target interface, so the 1159 # 2) Merged interface should be direct child of target interface, so the
1173 # children of merged interface are not affected by the merge. 1160 # children of merged interface are not affected by the merge.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s ' % self._idl_type 1342 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s ' % self._idl_type
1356 1343
1357 1344
1358 class TypeData(object): 1345 class TypeData(object):
1359 def __init__(self, clazz, dart_type=None, native_type=None, 1346 def __init__(self, clazz, dart_type=None, native_type=None,
1360 merged_interface=None, merged_into=None, 1347 merged_interface=None, merged_into=None,
1361 custom_to_dart=False, custom_to_native=False, 1348 custom_to_dart=False, custom_to_native=False,
1362 conversion_includes=None, 1349 conversion_includes=None,
1363 webcore_getter_name='getAttribute', 1350 webcore_getter_name='getAttribute',
1364 webcore_setter_name='setAttribute', 1351 webcore_setter_name='setAttribute',
1365 item_type=None, suppress_interface=False, is_typed_array=False): 1352 item_type=None, suppress_interface=False):
1366 self.clazz = clazz 1353 self.clazz = clazz
1367 self.dart_type = dart_type 1354 self.dart_type = dart_type
1368 self.native_type = native_type 1355 self.native_type = native_type
1369 self.merged_interface = merged_interface 1356 self.merged_interface = merged_interface
1370 self.merged_into = merged_into 1357 self.merged_into = merged_into
1371 self.custom_to_dart = custom_to_dart 1358 self.custom_to_dart = custom_to_dart
1372 self.custom_to_native = custom_to_native 1359 self.custom_to_native = custom_to_native
1373 self.conversion_includes = conversion_includes 1360 self.conversion_includes = conversion_includes
1374 self.webcore_getter_name = webcore_getter_name 1361 self.webcore_getter_name = webcore_getter_name
1375 self.webcore_setter_name = webcore_setter_name 1362 self.webcore_setter_name = webcore_setter_name
1376 self.item_type = item_type 1363 self.item_type = item_type
1377 self.suppress_interface = suppress_interface 1364 self.suppress_interface = suppress_interface
1378 self.is_typed_array = is_typed_array
1379 1365
1380 1366
1381 def TypedListTypeData(item_type): 1367 def TypedListTypeData(item_type):
1382 return TypeData( 1368 return TypeData(
1383 clazz='TypedList', 1369 clazz='TypedList',
1384 dart_type='List<%s>' % item_type, # TODO(antonm): proper typed_data interf aces. 1370 dart_type='List<%s>' % item_type, # TODO(antonm): proper typed_data interf aces.
1385 item_type=item_type, 1371 item_type=item_type)
1386 is_typed_array=True)
1387 1372
1388 1373
1389 _idl_type_registry = monitored.Dict('generator._idl_type_registry', { 1374 _idl_type_registry = monitored.Dict('generator._idl_type_registry', {
1390 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', 1375 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool',
1391 webcore_getter_name='hasAttribute', 1376 webcore_getter_name='hasAttribute',
1392 webcore_setter_name='setBooleanAttribute'), 1377 webcore_setter_name='setBooleanAttribute'),
1393 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
1394 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
1395 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 1378 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
1396 'unsigned short': TypeData(clazz='Primitive', dart_type='int', 1379 'unsigned short': TypeData(clazz='Primitive', dart_type='int',
1397 native_type='int'), 1380 native_type='int'),
1398 'int': TypeData(clazz='Primitive', dart_type='int'), 1381 'int': TypeData(clazz='Primitive', dart_type='int'),
1399 'unsigned int': TypeData(clazz='Primitive', dart_type='int', 1382 'unsigned int': TypeData(clazz='Primitive', dart_type='int',
1400 native_type='unsigned'), 1383 native_type='unsigned'),
1401 'long': TypeData(clazz='Primitive', dart_type='int', native_type='int', 1384 'long': TypeData(clazz='Primitive', dart_type='int', native_type='int',
1402 webcore_getter_name='getIntegralAttribute', 1385 webcore_getter_name='getIntegralAttribute',
1403 webcore_setter_name='setIntegralAttribute'), 1386 webcore_setter_name='setIntegralAttribute'),
1404 'unsigned long': TypeData(clazz='Primitive', dart_type='int', 1387 'unsigned long': TypeData(clazz='Primitive', dart_type='int',
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 type_name, type_data, dart_interface_name, self) 1572 type_name, type_data, dart_interface_name, self)
1590 1573
1591 if type_data.clazz == 'BasicTypedList': 1574 if type_data.clazz == 'BasicTypedList':
1592 dart_interface_name = self._renamer.RenameInterface( 1575 dart_interface_name = self._renamer.RenameInterface(
1593 self._database.GetInterface(type_name)) 1576 self._database.GetInterface(type_name))
1594 return BasicTypedListIDLTypeInfo( 1577 return BasicTypedListIDLTypeInfo(
1595 type_name, type_data, dart_interface_name, self) 1578 type_name, type_data, dart_interface_name, self)
1596 1579
1597 class_name = '%sIDLTypeInfo' % type_data.clazz 1580 class_name = '%sIDLTypeInfo' % type_data.clazz
1598 return globals()[class_name](type_name, type_data) 1581 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « no previous file | tools/dom/scripts/htmldartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698